Java Learning notes (vi)

Source: Internet
Author: User

Import Java.awt.BorderLayout;

Import Java.awt.ScrollPane;

Import java.awt.event.ActionEvent;

Import Java.awt.event.ActionListener;

Import Java.util.HashSet; Import Java.util.Random;

Import Javax.swing.JButton;

Import Javax.swing.JFrame;

Import Javax.swing.JLabel;

Import Javax.swing.JPanel;

Import Javax.swing.JTextArea;

public class CJ extends jframe{public CJ () {This.settitle ("lottery System");

This.setsize (250, 180);

This.setresizable (FALSE);

This.setlocationrelativeto (this);

This.setdefaultcloseoperation (Exit_on_close);

This.setcontentpane (Createcontentpanel ());

}

Private JPanel Createcontentpanel ()

{

JPanel panel=new JPanel (New BorderLayout ());

Panel.add (Borderlayout.center,createceterpanel ());

return panel;

}

Private JPanel Createceterpanel () {JPanel panel=new JPanel ();

Panel.add (New JLabel ("click Draw"), Jlabel.center);

JButton start=new JButton ("Start"); Panel.add (start);

ScrollPane sp = new ScrollPane (scrollpane.scrollbars_as_needed);

Final JTextArea area = new JTextArea ();

Sp.add (area); Panel.add (Sp,borderlayout.south);

Start.addactionlistener (New ActionListener ()

{

@Override public void actionperformed (ActionEvent arg0) {TODO auto-generated Method stub random random = new random (); Object[]values = new object[6]; HashSet HashSet = new HashSet ();Forint i =0;i <Values.length;i++) {int number = Random.nextint (1000) +1; Hashset.add (number); }values = Hashset.toarray (); Area.append ( "First prize Number:" +values[0] +  "\ n"); Area.append (" second Prize number is: "+values[1]+  "+values[2]+  "second Prize number:" +values[3] + "+values[4]+  "+values[5]+ return panel;}            

public static void Main (string[] args) {new CJ (). setvisible (True);

}

}

Java Learning notes (vi)

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.