求java小游戏源代码

导入Java . applet . applet;

导入Java . applet . audio clip;

导入Java . awt . dimension;

导入Java . awt . font;

导入Java . awt . toolkit;

导入javax . sound . sampled . audio file format;

导入javax . sound . sampled . audio system;

导入javax . swing . jframe;

导入javax . swing . jpanel;

导入Java . awt . rectangle;

导入javax . swing . border factory;

导入javax . swing . jbutton;

导入javax . swing . joptionpane;

导入javax . swing . js lider;

导入javax . swing . jlabel;

导入javax . swing . swing utilities;

导入javax . swing . ui manager;

导入javax . swing . event . change event;

导入javax . swing . event . change listener;

导入Java . awt . event . action event;

导入Java . awt . event . action listener;

导入Java . awt . event . key adapter;

导入Java . awt . event . key event;

导入Java . io . file;

导入Java . util . vector;

公共类Frame扩展JFrame实现Runnable {

JPanel contentPane

JPanel JPanel 1 = new JPanel();

JButton JButton 1 = new JButton();

JSlider JSlider 1 = new JSlider();

JLabel JLabel 1 = new JLabel();

JButton JButton 2 = new JButton();

JLabel JLabel 2 = new JLabel();

int计数= 1,快度= 80;//计算当前数字,以及快速光标的位置。

int zhengque = 0,CuO Wu = 0;

int rush[] = { 10,20,30 };//游戏中的关卡数量可以自由添加。列{10,20,30,40,50}

int rush _ count = 0;//记录结束号码

char list[] = { 'A ',' B ',' C ',' D ',' E ',' F ',' G ',' H ',' I ',' J ',' K ',' L ',

' m ',' N ',' O ',' P ',' Q ',' R ',' S ',' T ',' U ',' V ',' W ',' X ',' Y ',

z ',' 1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6 ',' 7 ',' 8 ',' 9 ' };//随机数可以自由添加。

向量号= new Vector();

String paiduan = " true

AudioClip Musci _安建,音乐_白石,音乐_呈贡;

公共框架(){

尝试{

setDefaultCloseOperation(EXIT _ ON _ CLOSE);

// -声音文件。

Musci _安建= Applet.newAudioClip(新文件(" sounds//anjian.wav ")

。toURL());

Music _白石= Applet.newAudioClip(新文件(" sounds//shibai.wav ")

。toURL());

music _ cheng gong = applet . newaudioclip(新文件(

“声音//chenggong.wav”)。toURL());

// -

JB init();

} catch(异常异常){

exception . printstacktrace();

}

}

/**

*组件初始化。

*

* @throws java.lang.Exception

*/

私有void jbInit()抛出异常{

content pane =(JPanel)get content pane();

content pane . set layout(null);

setSize(新维度(588,530));

setTitle(“帧标题”);

jpanel 1 . set border(border factory . createetchedborder());

jPanel1.setBounds(新矩形(4,4,573,419));

jpanel 1 . set layout(null);

jButton1.setBounds(新矩形(277,442,89,31));

jbutton 1 . settext(" Start ");

jbutton 1 . addactionlistener(new frame 1 _ jbutton 1 _ actionAdapter(this));

jSlider1.setBounds(新矩形(83,448,164,21));

jslider 1 . setmaximum(100);

jslider 1 . set minimum(1);

js lider 1 . setvalue(50);

jlabel 1 . settext(" speed ");

jLabel1.setBounds(新矩形(35,451,39,18));

jButton2.setBounds(新矩形(408,442,89,31));

jbutton 2 . settext(" end ");

jbutton 2 . addactionlistener(new frame 1 _ jbutton 2 _ action adapter(this));

jlabel 2 . settext(" Level 1:100 ");

jLabel2.setBounds(新矩形(414,473,171,21));

content pane . add(jpanel 1);

content pane . add(jbutton 2);

content pane . add(jbutton 1);

content pane . add(jslider 1);

content pane . add(jlabel 1);

content pane . add(jlabel 2);

this . addkey listener(new my listener());

jbutton 1 . addkey listener(new my listener());

jslider 1 . addkey listener(new my listener());

jslider 1 . addchangelistener(new change listener(){

public void state changed(change event e){

快速性= js lider 1 . getvalue();

}

});

}

公共无效运行(){

number . clear();

正缺= 0;

cuowu = 0;

paiduan = " true

while(count & lt;= rush[rush_count]) {

尝试{

Thread t =新线程(new Tthread());

t . start();

count+= 1;

thread . sleep(1000+(int)(math . random()* 2000));//下一个生产组的暂停时间

//最快是1。最慢2秒。

} catch (InterruptedException e) {

e . printstacktrace();

}

}

While (true) {//等待最后一个字符消失。

if (number.size() == 0) {

打破;

}

}

If (zhengque == 0) {//用于未来除法...如果都是对的或错的,就会出现错误。因此..

正雀= 1;

}

if (cuowu == 0) {

CuO Wu = 1;

}

If (paiduan.equals("true")) {//判断是否是自然结尾。

if(Zheng que/CuO Wu & gt;= 2) {

Joptionpane。显示消息对话框(空,“恭喜过关”);

rush _ count+= 1;//自动关闭1。

if(rush _ count & lt;rush.length) {

if(快速性& gt10) {//当速度大于10时,将加速度提升到-5。恐怕速度太快了。

快速性-= 5;//速度自动降低10毫秒。

jSlider1.setValue(快速性);//选择位置

}

Thread t =新线程(this);

t . start();

}否则{

Joption窗格。显示消息对话框(空,“牛B...你是清白的……”);

rush _ count = 0;

count = 0;

}

}否则{

Joptionpane。显示消息对话框(空,“请再接再厉”);

rush _ count = 0;

count = 0;

}

}否则{

rush _ count = 0;

count = 0;

}

}

public void jbutton 1 _ action performed(action event e){

Thread t =新线程(this);

t . start();

}

public void jbutton 2 _ action performed(action event e){

count = rush[rush _ count]+1;

paiduan = " flase

}

Tthread类实现Runnable {

公共无效运行(){

boolean fo = true

int Y = 0,X = 0;

JLabel show = new JLabel();

Show.setFont(新java.awt.Font("宋体",字体。平原,33));

jpanel 1 . add(show);

x = 10+(int)(math . random()* 400);

String参数= list[(int)(math . random()* list . length)]+" ";

Bean Bean = new Bean();

bean.setParameter(参数);

bean . set show(show);

number . add(bean);

show.setText(参数);

while (fo) {

// -数字向下移动。

show.setBounds(新矩形(X,Y += 2,33,33));

尝试{

Thread.sleep(快速);

} catch (InterruptedException e) {

e . printstacktrace();

}

如果(Y & gt= 419) {

fo =假;

for(int I = number . size()-1;我& gt= 0;我- ) {

Bean bn =((Bean)number . get(I));

if(parameter . equalsignorecase(bn . getparameter()){

CuO Wu+= 1;

JLabel2.setText("正确:"+zhengque+",错误:"+cuowu "

+“件”);

number . removeelementat(I);

music _ shibai . play();

打破;

}

}

}

}

}

}

MyListener类扩展KeyAdapter {

公共void按键(按键事件e) {

string uu = e . getkey char()+" ";

for(int I = 0;我& ltnumber . size();i++) {

Bean Bean =((Bean)number . get(I));

if(uu . equalsignorecase(bean . getparameter()){

正缺+= 1;

number . removeelementat(I);

bean.getShow()。set visible(false);

JLabel2.setText("正确:"+正缺+"个,错误:"+cuowu+"个");

music _ cheng gong . play();

打破;

}

}

musci _ anjian . play();

}

}

公共静态void main(String[] args) {

尝试{

ui manager . setlookandfeel(ui manager . getsystemlookandfeelclassname());

} catch(异常异常){

exception . printstacktrace();

}

框架Frame = new Frame();

dimension screenSize = toolkit . getdefaulttoolkit()。getScreenSize();

dimension frameSize = frame . getsize();

if(framesize . height & gt;screenSize.height) {

framesize . height = screensize . height;

}

if(framesize . width & gt;screenSize.width) {

framesize . width = screensize . width;

}

frame . set location((screensize . width-framesize . width)/2,

(screensize . height-framesize . height)/2);

frame . set visible(true);

}

}

class frame 1 _ jbutton 2 _ action adapter实现ActionListener {

专用帧适配器;

Frame 1 _ jbutton 2 _ action adapter(帧适配器){

this.adaptee = adaptee

}

public void action performed(action event e){

adaptee . jbutton 2 _ action performed(e);

}

}

类frame 1 _ jbutton 1 _ action adapter实现ActionListener {

专用帧适配器;

Frame 1 _ jbutton 1 _ action adapter(帧适配器){

this.adaptee = adaptee

}

public void action performed(action event e){

adaptee . jbutton 1 _ action performed(e);

}

}

类Bean {

字符串参数= null

JLabel show = null

公共JLabel getShow() {

回归秀;

}

公共void setShow(JLabel show) {

this.show = show

}

公共字符串getParameter() {

返回参数;

}

public void setParameter(字符串参数){

this.parameter =参数;

}

}