資源簡介
java寫的打字游戲。使用了多次按成,awt和swing,代碼注釋詳細,適合初學者。

代碼片段和文件信息
package?com.typegame;
import?javax.swing.*;
import?java.awt.*;
import?java.lang.Thread;
import?java.awt.event.*;
import?java.util.Vector;
import?java.util.Enumeration;
class?MyJLabel?extends?JLabel{
Mainframe?MyLframe;
char?keyP;
????Jt?one;
??class?Jt?extends?Thread{
????JLabel?Jtj;
????int?speed;
????int?xy;
????int?xun;
????int?killTop;
????boolean?Goin;
????JLabel?Kill;
????public?Jt(JLabel?JJ)
????{
??????Jtj=JJ;
??????Jtj.setFont(new?Font(“SansSerif“?0?1));
??????Jtj.setForeground(Color.WHITE);
??????x=(int)(Math.random()*500);
??????y=0;
??????xun=1;
??????
??????Goin=true;
????}
????
????
????/**
?????*?多線程調用的方法
?????*??@author?方強
?????*?
?????*/
????public?void?run()
????{
?????????speed=(int)(MyLframe.speed);
????????while(xun>0)
????????{?
???????????if(Goin==false)
???????????{
??????????? killTop=killTop-12;
??????????? Kill.setBounds(Jtj.getX()+12killTopJtj.getWidth()Jtj.getHeight());
??????????? synchronized(this)//線程同步安全鎖
??????????? {
??????????? if(Kill.getY()<(Jtj.getY()+30))
??????????? {
??????????? ???Kill.setVisible(false);
??????????? ???Jtj.setVisible(false);
??????????? ???this.stop();
??????????? }
??????????? }
???????????
???????????}
???????????y=y+4;//下降坐標Y
??????????Jtj.setBounds(xy?100?100);//設置下降
??????????
??????????//回收機制
???????????synchronized(this){
??????????? if(Goin==true)
??????????????{
???????????????if(MyLframe.qufen==false)
???????????????{?
??????????????????if(Jtj.getText().equals(String.valueOf(MyLframe.yeschar)))
????????????{
???????????? MyLframe.yeschar=‘0‘;
????????????????Kill=new?JLabel();
????????????????killTop=MyLframe.getHeight();
????????????????Kill.setIcon(new?ImageIcon(“GIF/Boom.gif“));
????????????????Kill.setForeground(Color.WHITE);
????????????????MyLframe.getContentPane().add(Killnull);
????????????????Goin=false;
????????????}
???????????}
???????????else
???????????{
???????????? if(Jtj.getText().equalsIgnoreCase(String.valueOf(MyLframe.yeschar)))
????????????{
???????????? Goin=false;
???????????? MyLframe.yeschar=‘0‘;
???????????? Kill=new?JLabel(“aa“);
????????????????killTop=MyLframe.getHeight();
????????????????Kill.setIcon(new?ImageIcon(“GIF/Boom.gif“));
????????????????Kill.setForeground(Color.WHITE);
????????????????MyLframe.getContentPane().add(Killnull);
????????????}
???????????}
????????????}
?????????
????????? ?if(y>500)//判斷是否下落到底
????????{
??????????Jtj.setVisible(false);
??????????xun=0;
??????????MyLframe.bad=MyLframe.bad+1;//下落到底,計數器加1
??????????MyLframe.badJ.setText(“你漏掉了:?“+String.valueOf(MyLframe.bad));//修改顯示漏掉個數
?????????this.stop();
????????}
????????try
????????{
??????????sleep(speed);
????????}
????????catch(Exception?e)
????????{
??????????e.toString();
????????}
????????}
??????}
????}
??}
??
??public?MyJLabel(char?nameMainframe?This)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????475??2014-05-19?10:53??TypeGame\.classpath
?????文件????????384??2014-05-19?10:08??TypeGame\.project
?????文件????????629??2014-05-19?10:08??TypeGame\.settings\org.eclipse.jdt.core.prefs
?????文件???????1955??2014-05-20?09:05??TypeGame\bin\com\typegame\Mainfr
?????文件???????2994??2014-05-20?09:05??TypeGame\bin\com\typegame\Mainfr
?????文件???????1438??2014-05-19?10:50??TypeGame\bin\com\typegame\Mainfr
?????文件????????633??2014-05-20?09:05??TypeGame\bin\com\typegame\Mainfr
?????文件???????3119??2014-05-20?09:05??TypeGame\bin\com\typegame\MyJLabel$Jt.class
?????文件????????709??2014-05-20?09:05??TypeGame\bin\com\typegame\MyJLabel.class
?????文件???????5487??2014-05-20?09:05??TypeGame\bin\com\typegame\startfr
?????文件????????652??2014-05-20?09:05??TypeGame\bin\com\typegame\startfr
?????文件????????655??2014-05-20?09:05??TypeGame\bin\com\typegame\startfr
?????文件????????739??2014-05-20?09:05??TypeGame\bin\com\typegame\startfr
?????文件????????651??2014-05-20?09:05??TypeGame\bin\com\typegame\startfr
?????文件???????2297??2006-03-02?14:20??TypeGame\GIF\A.gif
?????文件???????1748??2006-03-02?14:20??TypeGame\GIF\a_s.GIF
?????文件???????2282??2006-03-02?14:20??TypeGame\GIF\B.gif
?????文件????????261??2006-03-02?14:20??TypeGame\GIF\Boom.GIF
?????文件???????1720??2006-03-02?14:20??TypeGame\GIF\b_s.GIF
?????文件???????2301??2006-03-02?14:20??TypeGame\GIF\C.gif
?????文件???????1732??2006-03-02?14:20??TypeGame\GIF\c_s.GIF
?????文件???????2451??2006-03-02?14:20??TypeGame\GIF\D.gif
?????文件???????1714??2006-03-02?14:20??TypeGame\GIF\d_s.GIF
?????文件???????2384??2006-03-02?14:20??TypeGame\GIF\E.gif
?????文件???????1704??2006-03-02?14:20??TypeGame\GIF\e_s.GIF
?????文件???????1940??2006-03-02?14:20??TypeGame\GIF\F.gif
?????文件???????1714??2006-03-02?14:20??TypeGame\GIF\f_s.GIF
?????文件???????2424??2006-03-02?14:20??TypeGame\GIF\G.gif
?????文件???????1764??2006-03-02?14:20??TypeGame\GIF\g_s.GIF
?????文件???????2006??2006-03-02?14:20??TypeGame\GIF\H.gif
............此處省略55個文件信息
評論
共有 條評論