Java Edition typing practice game source

Source: Internet
Author: User

The code is as follows

Import Java.applet.applet;import java.applet.audioclip;import Java.awt.dimension;import Java.awt.Font;import Java.awt.toolkit;import Javax.swing.jframe;import Javax.swing.jpanel;import Java.awt.rectangle;import Javax.swing.borderfactory;import Javax.swing.jbutton;import Javax.swing.joptionpane;import Javax.swing.JSlider; Import Javax.swing.jlabel;import Javax.swing.uimanager;import Javax.swing.event.changeevent;import Javax.swing.event.changelistener;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.awt.event.keyadapter;import Java.awt.event.keyevent;import Java.io.file;import Java.util.Vector;public class        Main extends JFrame implements Runnable {private static final long serialversionuid = -2831332650077025158l;        JPanel ContentPane;        JPanel JPanel1 = new JPanel ();        JButton jButton1 = new JButton ();        JSlider jSlider1 = new JSlider ();        JLabel JLabel1 = new JLabel ();        JButton jButton2 = new JButton (); JLabEl JLabel2 = new JLabel ();         int count = 1, rapidity = 5;        int zhengque = 0, Cuowu = 0;         int rush[] = {10, 20, 30};         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 '};        Vector number = new vector ();        String Paiduan = "true";        AudioClip Musci_anjian, Music_shibai, Music_chenggong;                        Public Main () {try {setdefaultcloseoperation (exit_on_close); -----------------The sound file---------------------Musci_anjian = Applet.newaudioclip (The new file                        S//anjian.wav "). Tourl ());   Music_shibai = Applet.newaudioclip (New File ("Sounds//shibai.wav"). Tourl ());                     Music_chenggong = Applet.newaudioclip (New File ("Sounds//cheng                        Gong.wav "). Tourl ());                ---------------------------------------Jbinit ();                } catch (Exception Exception) {exception.printstacktrace (); }}/** * Initialize * * @throws Exception */private void Jbinit () throws                Exception {ContentPane = (JPanel) getcontentpane ();                Contentpane.setlayout (NULL);                SetSize (New Dimension (588, 530));                Settitle ("Frame Title");                Jpanel1.setborder (Borderfactory.createetchedborder ());                Jpanel1.setbounds (New Rectangle (4, 4, 573, 419));                Jpanel1.setlayout (NULL);                Jbutton1.setbounds (New Rectangle (277, 442, 89, 31));                Jbutton1.settext ("Start"); Jbutton1.addactionlistenER (new Frame1_jbutton1_actionadapter (this));                Jslider1.setbounds (New Rectangle (83, 448, 164, 21));                Jslider1.setmaximum (100);                Jslider1.setminimum (0);                Jslider1.setvalue (95);                Jlabel1.settext ("Speed");                Jlabel1.setbounds (New Rectangle (35, 451, 39, 18));                Jbutton2.setbounds (New Rectangle (408, 442, 89, 31));                Jbutton2.settext ("End");                Jbutton2.addactionlistener (New Frame1_jbutton2_actionadapter (this));                Jlabel2.settext ("First off: 10");                Jlabel2.setbounds (New Rectangle (414, 473, 171, 21));                Contentpane.add (JPANEL1);                Contentpane.add (JButton2);                Contentpane.add (JButton1);                Contentpane.add (JSlider1);                Contentpane.add (JLABEL1);                Contentpane.add (JLABEL2);                This.addkeylistener (New MyListener ());   Jbutton1.addkeylistener (New MyListener ());             Jslider1.addkeylistener (New MyListener ());                                Jslider1.addchangelistener (New ChangeListener () {public void statechanged (ChangeEvent e) {                        rapidity = 100-jslider1.getvalue ();        }                });                }/** * Main thread */public void run () {number.clear ();                Zhengque = 0;                Cuowu = 0;                Paiduan = "true"; while (Count <= Rush[rush_count]) {try {thread t = new Thread (n                                EW TThread ());                                T.start ();                                Count + = 1; Thread.Sleep (+ (int) (Math.random () * 500));                                Production group pause time//fastest 0.05 seconds. Slowest 0.5 seconds} catch (Interruptedexception e) {                        E.printstacktrace ();}} while (true) {//waits for the last character to disappear if (number.size () = = 0) {                        Break }} if (Zhengque = = 0) {//For later dividing: Errors can occur if all are correct or incorrect.                        So..                Zhengque = 1;                                } if (Paiduan.equals ("true")) {//Determine if it is natural to end if (Cuowu <= 2) {//Error no more than 2 clearance                                Joptionpane.showmessagedialog (NULL, "Congratulations on your pass"); Rush_count + = 1; Auto plus 1 off if (Rush_count < rush.length) {if (RAPI                                                Dity > 10) {//when the speed is greater than 10, the acceleration is at-5. Afraid of speed too fast rapidity-= 5;//speed automatically minus 10 milliseconds Jslider1.setvalue (rapidity);          Select Location} thread t = new Thread (this);                              T.start (); } else {joptionpane.showmessagedialog (null, "cow b ...                                        You have cleared the customs. ");                                        Rush_count = 0;                                Count = 0;                                }} else {joptionpane.showmessagedialog (null, "Please re-connect again");                                Rush_count = 0;                        Count = 0;                        }} else {rush_count = 0;                Count = 0;                }} public void jbutton1_actionperformed (ActionEvent e) {Thread t = new Thread (this);        T.start ();                } public void jbutton2_actionperformed (ActionEvent e) {count = Rush[rush_count] + 1;        Paiduan = "Flase"; }/** * Characters Move Down thread */class TthRead implements Runnable {public void Run () {Boolean fo = true;                        int Y = 0, X = 0;                        JLabel show = new JLabel ();                        Show.setfont (New Java.awt.Font ("The song Body", Font.plain, 33));                        Jpanel1.add (show);                        X = ten + (int) (Math.random () * 400);                        String parameter = list[(int) (Math.random () * list.length)] + "";                        Bean bean = new Bean ();                        Bean.setparameter (parameter);                        Bean.setshow (show);                        Number.add (Bean);                        Show.settext (parameter);                                while (FO) {//---------------------characters Move Down--------------------                                Show.setbounds (New Rectangle (X, Y + = 2, 33, 33));     try {thread.sleep (rapidity);                           } catch (Interruptedexception e) {e.printstacktrace ();                                        } if (Y >= 419) {                                        fo = false; for (int i = Number.size ()-1; I >= 0; i--) {Bean bn = (bean) number.                                                Get (i));                                                        if (Parameter.equalsignorecase (Bn.getparameter ())) {Cuowu + = 1;                                                                        Jlabel2.settext ("Correct:" + Zhengque + "One, Error:" + Cuowu                                                        + "one");                                                        Number.removeelementat (i);                                                        Music_shibai.play ();   Break                                             }                                        }                                }  }}}/** * Keyboard listener * */class MyListener Extends Keyadapter {public void keypressed (KeyEvent e) {String UU = E.getkeychar (                        ) + "";                                for (int i = 0; i < number.size (); i++) {Bean bean = (bean) number.get (i)); if (Uu.equalsignorecase (Bean.getparameter ())) {Zhengque + = 1                                        ;                                        Number.removeelementat (i);                                        Bean.getshow (). setvisible (false);                                        Jlabel2.settext ("Correct:" + Zhengque + "One, Error:" + Cuowu + "x");                                        Music_chenggong.play ();             Break                   }} musci_anjian.play (); }} public static void Main (string[] args) {try {Uimanager.setlookan                Dfeel (Uimanager.getsystemlookandfeelclassname ());                } catch (Exception Exception) {exception.printstacktrace ();                } Main frame = new Main ();                Dimension screensize = Toolkit.getdefaulttoolkit (). Getscreensize ();                Dimension framesize = Frame.getsize ();                if (Framesize.height > Screensize.height) {framesize.height = Screensize.height;                 } if (Framesize.width > Screensize.width) {framesize.width = Screensize.width;                } frame.settitle ("Java Edition typing Practice software"); Frame.setlocation ((screensize.width-framesize.width)/2, (sCreensize.height-framesize.height)/2);        Frame.setvisible (TRUE);        }}class Frame1_jbutton2_actionadapter implements ActionListener {private Main adaptee;        Frame1_jbutton2_actionadapter (Main adaptee) {this.adaptee = Adaptee;        } public void actionperformed (ActionEvent e) {adaptee.jbutton2_actionperformed (e);        }}class Frame1_jbutton1_actionadapter implements ActionListener {private Main adaptee;        Frame1_jbutton1_actionadapter (Main adaptee) {this.adaptee = Adaptee;        } public void actionperformed (ActionEvent e) {adaptee.jbutton1_actionperformed (e);        }}/*** falling character class * */class Bean {String parameter = null;        JLabel show = null;        Public JLabel Getshow () {return show;        } public void Setshow (JLabel show) {this.show = Show; } public String GetParameter () {REturn parameter;        } public void Setparameter (String parameter) {this.parameter = parameter; }}

  
<ignore_js_op>

Detailed Description: http://java.662p.com/thread-3797-1-1.html

Java Edition typing practice game source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.