Sixth time Assignment

Source: Internet
Author: User

Lottery Program: With ArrayList class and Random class
Import java.awt.*;

Import javax.swing.*;

Import java.awt.event. ;
Import Java.util.
;
Import java.util.List;

public class Jrandom extends JFrame {
Private JFrame frame;
Private JButton Startbutton;

PublicJrandom() {makeframe (); Frame.pack (); Frame.setvisible (true); Frame.setsize (400,215); Frame.setlocation (550,350); Frame.setdefaultcloseoperation (jframe.exit_on_close);}PrivatevoidMakeframe() {frame =New JFrame ("Draw a prize!" "); ImageIcon ImageIcon0 =New ImageIcon ("T/1.png"); Frame.seticonimage (Imageicon0.getimage ()); Container ContentPane = Frame.getcontentpane (); Startbutton =New JButton (); ImageIcon ImageIcon1 =New ImageIcon ("T/3.png"); ImageIcon ImageIcon2 =New ImageIcon ("T/4.png"); ImageIcon ImageIcon3 =New ImageIcon ("T/5.png"); Startbutton.seticon (ImageIcon1);Set button Shape Startbutton.setrollovericon (imageIcon2);Set the mouse over button image Startbutton.setpressedicon (ImageIcon3);Sets the shape of the mouse button pressed Startbutton.setmargin (New Insets (0,0,0,0));Sets the number of pixels between the button border and the content of the border startbutton.setborderpainted (FALSE);Do not draw bordersButton Event Listener Startbutton.addactionlistener (New ActionListener () {@OverridePublicvoidActionperformed(ActionEvent e) {TODO auto-generated Method Stub Makechoujiang (); } }); Contentpane.add (Startbutton, borderlayout.center);}PrivatevoidMakechoujiang() {Double Basenum =0.50; String Product ="100 yuan, 200 yuan, 500 yuan, 1000 Yuan"; String num ="30,20,5,3"; String[] p = product.split (","); string[] n = num.split (","); Random ran =New Random ();Double base = ran.nextdouble ();if (Base > Basenum) {imageicon ImageIcon =New ImageIcon ("T/2.png"); Joptionpane.showmessagedialog (Frame,"Please continue your efforts!" ","Lottery Results", joptionpane.plain_message, ImageIcon);Return } list<string>List =New Arraylist<string> ();for (int i =0; i < p.length; i++) {for (Int J =0; J < Integer.parseint (N[i]); J + +) {list.add (P[i]);} } //upset the prize pool data int L = ran.nextint ( List.size ()); ImageIcon ImageIcon = new ImageIcon ( "t/1.png"); Joptionpane.showmessagedialog (frame,  "Congratulations" + list.get (L) +  "Yo!!",  "lottery results", joptionpane.plain_message, ImageIcon);} public static void main (string[] args) { //TODO auto-generated Method stub new jrandom ();}   

}
The program interface is as follows:

Sixth time Assignment

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.