Java Development--game 24 points

Source: Internet
Author: User
Tags gettext

Also relatively simple, poor writing, the code used in the lookandfell,quaqua8.0 bag

Package com. Game24;import java.awt.container;import java.awt.dimension;import Java.awt.flowlayout;import java.awt.GridLayout; Import Java.awt.toolkit;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Javax.swing.jbutton;import Javax.swing.jframe;import Javax.swing.jlabel;import Javax.swing.JOptionPane;import Javax.swing.jpanel;import Javax.swing.jpopupmenu;import Javax.swing.jrootpane;import Javax.swing.JTextArea;import Javax.swing.jtextfield;import Javax.swing.uimanager;import Javax.swing.unsupportedlookandfeelexception;import ch.randelshofer.quaqua.jaguar.quaqua15jaguarlookandfeel;/* #####################################################                ####### # # # "name": Game-24 points # # "Author": Sevck (a man who writes code very handsome) # # "team": Network knife # # "Home": Http://sevck.lofter.com # # "date": 2015-10-17 # # "function": 24 points, and the button cannot be duplicated, and And the result cannot be edited # # # ############################################################ #┏┓┏┓#┏┛┻━━━┛┻┓#┃┃#┃━┃#┃┳┛┗┳┃ #┃┃#┃ ' ┻ ' ┃#┃┃#┗━┓┏━┛#####┃┃code is far awa Y from bugs with the animal protecting. #####┃┃ God beast Bless, Code no bug.  #####┃┗━━━━━┓#####┃┣┓#####┃┏┛#####┗┓┓┏━┳┓┏┛#######┃┫┫ ┃┫┫#######┗┻┛┗┻┛############################################################ */public class Game24 extends JFrame {s Tatic JButton b[] = null;//random number button JButton law[] = new jbutton[] {new JButton ("+"), New JButton ("-"), New JButton ("*"), new JButton ("/")};//arithmetic button JLabel label = new JLabel ("Result:"); JTextArea Text = new JTextArea (1, 15); JButton of[] = new jbutton[] {new JButton ("OK"), New JButton ("refresh")};static int mark = 0; JLabel point = new JLabel ("Current score:" + mark); JPanel JP = new JPanel (); JPanel JP2 = new JPanel (); JPanel jp3 = new JPanel (); JPanel JP4 = new JpaneL (); JPanel JP5 = new JPanel (); String reg = "[0-9]{1,2}. [0-9] {.}. [0-9] {.}. [0-9]  {6-2char} ";//One + 4 * c[] = new Char[3];p ublic static String GetNumber () {//random number method int i = (int) (Math.random () * 13 + 1); String number = string.valueof (i); return number;} public static void Setbname () {//N1=game24.getnumber ();//}public Game24 () {setundecorated (true); Setdefaultcloseoperation (3); Setfocusablewindowstate (true); JRootPane RP = Getrootpane (); setvisible (true); Rp.setwindowdecorationstyle (jrootpane.frame);//System.out.println ( Game24.getnumber ()); b = new jbutton[] {new JButton (Game24.getnumber ()), New JButton (Game24.getnumber ()), New JButton ( Game24.getnumber ()), New JButton (Game24.getnumber ())};init (); public void init () {this.settitle ("24-point--by:sevck"); This.setvisible (true);//Whether Visual this.setdefaultcloseoperation (3); /Close Window mode this.setsize (700, 330);//Set Window size this.setresizable (FALSE);//Set whether the panel size can be modified this.setlocationrelativeto (NULL); This.setlayout (New GridLayout (5, 5, 5, 5));//Set layout to flow layout This.setloCationrelativeto (null); for (int i = 0; i < b.length; i++) {Jp.add (b[i]);} for (int i = 0; i < law.length; i++) {Jp2.add (law[i]);} Container CP = This.getcontentpane (); Cp.add (JP); Cp.add (JP2); text.seteditable (false); Jp3.add (label); Jp3.add (text); Cp.add (JP3); Jp4.add (of[0]); Jp4.add (of[1)); Cp.add (JP4); Jp5.add (point); Cp.add (JP5); B[0].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO auto-generated method stubb[0]. SetEnabled (FALSE); String str = B[0].gettext (); text.append (str);}}); B[1].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO Auto-generated method Stubb[1].setenabled (false); String str = B[1].gettext (); text.append (str);}}); B[2].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO Auto-generated method Stubb[2].setenabled (false); String str = B[2].gettext (); text.append (str);}}); B[3].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO auto-generated method stubb[3].setenabled (false); String str = B[3].gettext (); text.append (str);}}); Law[0].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO auto-generated method Stubstring str = Law[0].gettext (); text.append (str);}); Law[1].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO auto-generated method Stubstring str = Law[1].gettext (); text.append (str);}); Law[2].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO auto-generated method Stubstring str = Law[2].gettext (); text.append (str);}); Law[3].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO auto-generated method Stubstring str = Law[3].gettext (); text.append (str);}); O F[0].addactionlistener (new ActionListener () {/////////int dian; @Overridepublic void actionperformed (ActionEvent e) {//TODO auto-generated method stubstring str = Text.gettext (); Boolean z = str.matches (reg);//compliance Operation rule if (z) {String rule = Text.gettext ();//System.out.println (rule); String sp = "[^0-9]"; String num[] = rule.split (sp); Get 4 numbers//for (int i = 0; i < num.length; i++) {//System.out.println (Num[i]);//}///////////////////////////////str ing faze = "[0-9]+"; string[] AA = Rule.split (faze);//for (int j = 0; J < Aa.length; J + +) {//Get 3 Operators//SYSTEM.OUT.PRINTLN (Aa[j]);//}//// int num1 = Integer.parseint (num[0]); int num2 = Integer.parseint (num[1]); int num3 = Integer.parseint (num[2]); int num4 = Integer.parseint (num[3]); int d1 = GETJG (aa[1], NUM1, num2); int d2 = GETJG (aa[2], D1, n UM3); int d3 = GETJG (Aa[3], D2, NUM4); if (D3 = =) {Joptionpane.showmessagedialog (null, "Congratulations, go to the next level!) Mark = Mark + 5;point.settext ("Current score:" + mark); B[0].settext (Game24.getnumber ());//Refresh B[1].settext (Game24.getnumber ( ); B[2].settext (Game24.getnumber ()); B[3].settext (Game24.getnumber ()); for (int i = 0; I <= 3; i++) {b[i].setenabled (true); Text.settext ("");}} else {Joptionpane.showmessagedialog (null, "No, Think again ~"); b[0].setenabled (true); b[1].setenabled (true); B[2]. SetEnabled (True); b[3].setenabled (True);}} else {Joptionpane.showmessagedialog (null, "wrong operation step!) ");}} public int GETJG (String fh, int s1, int s2) {if (Fh.equalsignorecase ("+")) {dian = s1 + s2;} if (Fh.equalsignorecase ("-")) {dian = s1-s2;} if (Fh.equalsignorecase ("*")) {dian = S1 * s2;} if (Fh.equalsignorecase ("/")) {dian = s1/s2;} return Dian;}); O F[1].addactionlistener (new ActionListener () {@Overridepublic void actionperformed (ActionEvent e) {//TODO Auto-generated method stub//Game24.setbname (); B[0].settext (Game24.getnumber ()); B[1].settext (Game24.getNumber ()); B[2].settext (Game24.getnumber ()); B[3].settext (Game24.getnumber ()); for (int i = 0; I <= 3; i++) {b[i].setenabled (True ); Text.settext ("");}}); public static void Main (string[] args) {system.setproperty ("Quaqua.tablayoutpolicy", "wrap"); try {Uimanager.setlOokandfeel (Ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel ());} catch (Unsupportedlookandfeelexception e) {//TODO auto-generated catch block}new Game24 ();}}

  

Java Development--game 24 points

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.