Java 6th time Job

Source: Internet
Author: User

Import Java.awt.borderlayout;import java.awt.color;import Java.awt.flowlayout;import Java.awt.Insets;import Java.awt.label;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.util.HashSet; Import Java.util.random;import javax.swing.imageicon;import Javax.swing.jbutton;import Javax.swing.JFrame;import Javax.swing.jlabel;import Javax.swing.joptionpane;import Javax.swing.jpanel;import Javax.swing.JTextArea;import    Javax.swing.jtextfield;public class Choujiang extends JFrame {private JPanel imagepanel, p2;    Private ImageIcon background, Anniu;    Private JButton Kaishi, one, second, third, four, five, six;    protected Object S;    public static int b = 1;    Public JTextField JT;    Public String text= "record: \ n";    public void Run () {System.out.println ("1"); } public Choujiang () {background = new ImageIcon ("img/1.jpg");//Background image anniu = new ImageIcon ("Img/2.png")        ;   JLabel label = new JLabel (background);//Display the background image in a label     Label.setbounds (0, 0, background.geticonwidth (), Background.geticonheight ());        Convert the content pane to JPanel, otherwise you cannot use method Setopaque () to make the contents pane transparent Imagepanel = (JPanel) this.getcontentpane ();        Imagepanel.setopaque (FALSE);        The default layout manager for the Contents pane is borderlayout Kaishi = new JButton (Anniu);        Kaishi.setsize (45, 40);        Kaishi.setlocation (168, 249);        Kaishi.setbackground (Color.yellow);  Kaishi.addactionlistener (new ActionListener () {@Override public void actionperformed (ActionEvent e)                    {//TODO auto-generated Method stub if (b<=3) {b++;                    T t = new t ();                    T.run ();                    Random r = new Random ();                    int a = R.nextint (6) + 1;                    Chushihua ();                        if (a = = 1) {one.setbackground (color.yellow);              Jt.settext ("Congratulations you won the first prize");          text=text+ "Congratulations on getting the first prize \ n";                        } else if (a = = 2) {second.setbackground (color.yellow);                        Jt.settext ("Congratulations to you for the second Prize");                    text=text+ "Congratulations on receiving the second prize \ n";                        } else if (a = = 3) {third.setbackground (color.yellow);                        Jt.settext ("Congratulations to you for the third Prize");                    text=text+ "Congratulations on getting the third prize";                        } else if (a = = 4) {four.setbackground (color.yellow);                        Jt.settext ("Congratulations on your winning the award of Excellence");                    text=text+ "Congratulations on your winning the award of Excellence \ n";                        } else if (a = = 5) {five.setbackground (color.yellow);                        Jt.settext ("Congratulations on your getting one more");                    text=text+ "Congratulations on your getting one more time \ n";                        } else if (a = = 6) {six.setbackground (color.yellow);                      Jt.settext ("Don't lose heart, next time refueling");  Text=text+ "Don't lose heart, next time refueling \ \"; }}else{Joptionpane.showmessagedialog (Imagepanel, "You have run out of draws, please click to exit!") "," Closed!                ", joptionpane.warning_message);         }                            }        });         Random random = new random ();         Object[] values = new OBJECT[6];           HashSet HashSet = new HashSet ();               for (int i = 0;i < values.length;i++) {int number = Random.nextint (1000) + 1;           Hashset.add (number);                              } values = Hashset.toarray ();        one = new JButton ("a");        One.setmargin (New Insets (0, 0, 0, 0));        One.setsize (30, 30);        One.setlocation (108, 174);        One.setbackground (Color.pink);        Second = new JButton ("two");        Second.setmargin (New Insets (0, 0, 0, 0));        Second.setsize (30, 30);        Second.setlocation (219, 162);        Second.setbackground (Color.pink); Third = new JButton ("Three");        Third.setmargin (New Insets (0, 0, 0, 0));        Third.setsize (30, 30);        Third.setlocation (305, 249);        Third.setbackground (Color.pink);        four = new JButton ("IV");        Four.setmargin (New Insets (0, 0, 0, 0));        Four.setsize (30, 30);        Four.setlocation (248, 332);        Four.setbackground (Color.pink);        five = new JButton ("Five");        Five.setmargin (New Insets (0, 0, 0, 0));        Five.setsize (30, 30);        Five.setlocation (128, 349);        Five.setbackground (Color.pink);        six = new JButton ("six");        Six.setmargin (New Insets (0, 0, 0, 0));        Six.setsize (30, 30);        Six.setlocation (48, 259);         Six.setbackground (Color.pink);        JT = new JTextField ();        Jt.setsize (332, 32);        Jt.setlocation (36, 565);        Imagepanel.setlayout (NULL);        Imagepanel.add (Kaishi);        Imagepanel.add (one);        Imagepanel.add (second);        Imagepanel.add (third);        Imagepanel.add (four); Imagepanel.add (FIVe);        Imagepanel.add (six);        Imagepanel.add (JT);        This.getlayeredpane (). setlayout (NULL); Add a background image to the bottom of the hierarchical pane as Background this.getlayeredpane (). Add (Label, new Integer (Integer.min_value));//THIS.SETDEFAULTC        Loseoperation (Jframe.exit_on_close);        This.setsize (Background.geticonwidth (), Background.geticonheight () +42);    This.setvisible (TRUE);        } public static void Main (string[] args) {Choujiang t = new Choujiang ();    T.setvisible (TRUE);        } public void Chushihua () {one.setbackground (color.pink);        Second.setbackground (Color.pink);        Third.setbackground (Color.pink);        Four.setbackground (Color.pink);        Five.setbackground (Color.pink);            Six.setbackground (Color.pink);    } public JTextField Getjt () {return JT;            }}class T extends Thread {public void run () {try {sleep (1000);        System.out.println ("a");          } catch (Interruptedexception e) {  TODO auto-generated Catch block E.printstacktrace (); }    }

This week's assignment requires a lottery system that limits the number of lottery draws and does not duplicate the prize, since the final design of our group last semester is a lottery system, so this assignment is just a part of the code to improve, mainly to add a limited number of code. Run the results.

Java 6th time Job

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.