Two-color ball lottery system written in Java

Source: Internet
Author: User



Step 1: This is our two-color ball main class, including the interface design!


Package ball; import java. awt. borderLayout; import java. awt. color; import java. awt. font; import java. awt. image; import java. awt. toolkit; import java. awt. event. actionEvent; import java. awt. event. actionListener; import java.net. URL; import javax. swing. JButton; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. JOptionPane; import javax. swing. JPanel; import javax. swing. JTextField;/***** @ autho R huyongjian Oracle (Compus Solution Group) * @ Date 2013-7-18 * @ version 2.0 * @ since JDK1.6 recommended) Copy Right Information compus solution group ide: Eclipse class: ball two-color Ball */public class Ball extends JFrame implements ActionListener {JPanel pn1, pn2, pn3; // The form has three JTextField tf1, tf2; // two text boxes JLabel lb1, lb2, lb3; // JButton btn1, btn2, btn3; // The three buttons boolean flag = false; // define a flag Ball () {pn1 = new JPanel (); pn2 = New JPanel (); pn3 = new JPanel (); tf1 = new JTextField ("red ball", 20); // length 20 tf2 = new JTextField ("blue ball ", 8); // length 8 btn1 = new JButton ("START"); btn2 = new JButton ("stop"); btn3 = new JButton ("about"); this. setLayout (new BorderLayout (); this. add (pn1, BorderLayout. NORTH); // border layout of the form, which is CENTER this by default. add (pn2, BorderLayout. CENTER); this. add (pn3, BorderLayout. SOUTH); lb2 = new JLabel ("six balls in red ball from 1 to 33"); lb2.setForegroun D (Color. black); lb3 = new JLabel ("select a ball from 1 to 16"); lb3.setForeground (Color. black); // FlowLayout flow = new FlowLayout (); // pn1.setLayout (flow); Font font1 = new Font ("", Font. BOLD, 12); pn1.add (lb2); pn1.add (tf1); tf1.setForeground (Color. red); tf1.setFont (font1); pn1.add (lb3); pn1.add (tf2); tf2.setForeground (Color. blue); tf2.setFont (font1); Font fnt = new Font (" 文 ", Font. BOLD, 20); lb1 = new JLabel ("The two-color ball pool has reached 458398235 yuan. Good luck !!! "); Lb1.setFont (fnt); lb1.setForeground (Color. red); pn2.add (lb1); pn3.add (btn1); pn3.add (btn2); pn3.add (btn3); merge (this); btn2.addActionListener (this); btn3.addActionListener (this); this. setSize (600,150); // form size // center the display position this. setLocationRelativeTo (null); // center the display position // modify the icon URL in the upper left corner of java = this. getClass (). getResource ("ball.png"); Image img = Toolkit. getdefatooltoolkit (). getImage (url); this. setIconImage (img); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); // when the program is closed, run javaw.exe this. setTitle ("two-color automatic lottery"); this. setVisible (true); this. setResizable (false); start () ;}@ Override public void actionreceivmed (ActionEvent e) {// TODO Auto-generated method stub if (e. getSource () = btn1) {btn1.setEnabled (false); btn2.setEnabled (true); flag = true;} if (e. getSource () = btn2) {btn2.setEnabled (false); btn1.setEnabled (true); flag = false;} if (e. getSource () = btn3) {JOptionPane. showMessageDialog (null, "

Step 2: Next is our main function class, which calls the Ball () method we wrote!

Package ball;/***** @ author huyongjian Oracle (Compus Solution Group) * @ Date 2013-7-18 * @ version 2.0 * @ since JDK1.6 recommended) Copy Right Information compus solution group ide: eclipse class: BallTest test */public class BallTest {public static void main (String [] args) {new Ball ();}}

For more source code written in Java, please go to the group: 160243674 -- Java!

Effect display:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/11260HS4-0.png "title =" Ball.png "/>


This article from the "promise always attachment Xiao Chai," blog, please be sure to keep this source http://1936625305.blog.51cto.com/6410597/1263390

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.