資源簡介
java多線程控制的賽跑程序,包括打包好的可執(zhí)行程序
代碼片段和文件信息
import?java.awt.*;
import?java.awt.event.*;
import?java.util.Random;??//引入隨機(jī)數(shù)類
import?javax.swing.*;
public?class?RaceGame?extends?frame?implements?ActionListenerRunnable
{
//聲明組件
Button?b_start;
Button?b_exit;
Button?b_register;
Label?l_score;
JLabel?l_titlel_backl_cheer;
Icon?i_backi_xli_fgi_xldi_fgd;
TextArea?t_report;
//聲明勝者變量
public?static?String?winer;
Player?xlfg;//聲明選手對象
Thread?thr;//聲明線程
int?score;//終點(diǎn)距離
RaceGame(final?String?s)
{
super(s);
//使用坐標(biāo)布局
setLayout(null);
score=500;//終點(diǎn)距離
//初始化個(gè)組件
//并用setBounds方法布局
b_start=new?Button(“開始“);
b_exit=new?Button(“退出“);
b_start.setBounds(220704020);
b_exit.setBounds(280704020);
b_start.addActionListener(this);
b_exit.addActionListener(this);
l_title=new?JLabel(“賽???跑“);
Font?f=new?Font(“華文新魏“Font.PLAIN24);
l_title.setFont(f);
l_title.setForeground(Color.white);
l_title.setBounds(236408025);
l_score=new?Label(“?終點(diǎn)線“);
l_score.setBounds(score+5516550150);
l_score.setBackground(Color.blue);
l_score.setForeground(Color.white);
l_cheer=new?JLabel(““);
l_cheer.setBounds(5034052050);
l_cheer.setBackground(Color.magenta);
l_cheer.setForeground(Color.yellow);
l_cheer.setFont(f);
l_cheer.setVisible(false);
i_back=new?ImageIcon(“pave.jpg“);
l_back=new?JLabel(i_back);
l_back.setBounds(0?0?640?420);
//實(shí)現(xiàn)兩個(gè)參賽選手對象
xl=new?Player(“迅~~~~雷“19030score);
fg=new?Player(“網(wǎng)際快車“26030score);
//初始化對象
xl.body.setBackground(Color.white);
fg.body.setBackground(Color.red);
i_xl=new?ImageIcon(“xls.gif“);
xl.body.setIcon(i_xl);
i_fg=new?ImageIcon(“fgs.gif“);
fg.body.setIcon(i_fg);
i_xld=new?ImageIcon(“xld.gif“);
i_fgd=new?ImageIcon(“fgd.gif“);
//狀態(tài)報(bào)告板
t_report=new?TextArea(““?10?101);
t_report.setBounds(5003014080);
//實(shí)現(xiàn)線程
thr=new?Thread(this);
thr.start();
//添加組件
add(t_report);
add(l_title);
add(l_score);
add(l_cheer);
add(b_start);
add(b_exit);
add(xl.body);
add(fg.body);
add(l_back);
setBackground(Color.black); //窗體背景色
setBounds(6060640420);//窗體大小
setResizable(false);//固定大小
setVisible(true);//可見
//窗體適配器
addWindowListener(
???????????new?WindowAdapter(){
???????????????public?void?windowClosing(WindowEvent?e){
??????????????????System.exit(0);
???????????????}
???????????}
??????);?
}
public?void?actionPerformed(final?ActionEvent?e)
{
if(e.getSource()==b_start)//點(diǎn)擊開始按鈕
{
l_cheer.setVisible(false);//隱藏慶祝
//選手復(fù)位
xl.reset();
fg.reset();
//改變狀態(tài)圖標(biāo)
fg.body.setIcon(i_fgd);
xl.body.setIcon(i_xld);
//激活線程
xl.thr.resume();
fg.thr.resume();
thr.resume();
//輸出報(bào)告
t_report.append(xl.name+“的啟動(dòng)速度為:“+xl.speed+“\n“+fg.name+“的啟動(dòng)速度為:“+fg.speed+“\n“);
}
if(e.getSource()==b_exit)
System.exit(0);//退出
}
public
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????226??2007-06-21?19:20??第三題:賽跑\.classpath
?????文件????????384??2007-06-21?19:20??第三題:賽跑\.project
?????文件???????1652??2007-07-01?17:21??第三題:賽跑\Pla
?????文件????????585??2007-07-01?17:21??第三題:賽跑\RaceGame$1.class
?????文件???????4907??2007-07-01?17:21??第三題:賽跑\RaceGame.class
?????文件???????5449??2007-07-01?17:21??第三題:賽跑\RaceGame.java
?????文件????????443??2007-07-01?17:21??第三題:賽跑\RaceGameEx.class
?????文件???????1307??2007-06-30?21:18??第三題:賽跑\打包好的可執(zhí)行程序在此\fgd.gif
?????文件???????2070??2007-06-30?21:10??第三題:賽跑\打包好的可執(zhí)行程序在此\fgd1.gif
?????文件????????777??2007-06-30?19:19??第三題:賽跑\打包好的可執(zhí)行程序在此\fgs.gif
?????文件???????1350??2007-07-01?16:12??第三題:賽跑\打包好的可執(zhí)行程序在此\jrace.jsmooth
?????文件?????404696??2007-06-30?17:28??第三題:賽跑\打包好的可執(zhí)行程序在此\pave.jpg
?????文件?????451584??2007-07-01?16:12??第三題:賽跑\打包好的可執(zhí)行程序在此\race.exe
?????文件???????7393??2007-07-01?16:06??第三題:賽跑\打包好的可執(zhí)行程序在此\race.jar
????..A.SH.?????17408??2008-04-05?20:14??第三題:賽跑\打包好的可執(zhí)行程序在此\Thumbs.db
?????文件???????1690??2007-06-30?17:52??第三題:賽跑\打包好的可執(zhí)行程序在此\xld.GIF
?????文件????????769??2007-06-30?17:43??第三題:賽跑\打包好的可執(zhí)行程序在此\xls.GIF
?????目錄??????????0??2008-04-05?20:14??第三題:賽跑\打包好的可執(zhí)行程序在此
?????目錄??????????0??2008-02-02?00:30??第三題:賽跑
-----------?---------??----------?-----??----
???????????????902690????????????????????19
評論
共有 條評論