Java Jobs (vi)

Source: Internet
Author: User

Using the card game taught by the teacher, I made the code improvements into a lottery system and displayed the results in a graphical user interface.

Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;Importjava.util.ArrayList;Importjava.util.Collections;ImportJava.util.Random;ImportJavax.swing.JButton;ImportJavax.swing.JFrame;ImportJavax.swing.JTextArea; Public classReward {ArrayList<Integer>lists;  PublicArraylist<integer>deal () {if(lists==NULL) {Lists=NewArraylist<integer>();  for(intI =1;i<200;i++) {lists.add (i);        }} collections.shuffle (lists); returnlists; }              Public voidrun () {JFrame frm=NewJFrame ("lottery Platform");//Create a FrameJButton BTN =NewJButton ("Sweepstakes");//Create button        FinalJTextArea Text =NewJTextArea ();//Create a text boxText.setbounds (130, 40, 200, 100);//Set the text box size positionText.seteditable (false);//Setting a text box is not editable                /** Add Event response for Button*/Btn.addactionlistener (NewActionListener () { Public voidactionperformed (ActionEvent e) {Random R=NewRandom (); intA = R.nextint (200); Text.settext ("First Prize:" + Lists.get (a) + "No. \ n");                   Lists.remove (a);  for(intj=1;j<=3;j++) {a= R.nextint (200); Text.append ("Second Prize:" +lists.get (a) + "No. \ n");                   Lists.remove (a);                }            }}); Btn.setbounds (200, 170, 60, 30);//Set Button size positionFrm.add (text);//Add a text box to a frameFrm.add (BTN);//Add a button to the frameFrm.setbounds (200,300, 450, 300);//Set Frame size positionFrm.setlayout (NULL);//Set Layout modeFrm.setvisible (true);//set to visible           }         Public Static voidMain (string[] args) {reward rew=Newreward ();     Rew.deal ();    Rew.run (); }}

Java Jobs (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.