Java Draw Small Program

Source: Internet
Author: User
Tags set background

 Packagecom.test;ImportJava.awt.Color;ImportJava.awt.Font;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJava.util.Random;ImportJavax.swing.JButton;ImportJavax.swing.JFrame;ImportJavax.swing.JLabel;ImportJavax.swing.JPanel;ImportJavax.swing.JTextArea;ImportJavax.swing.JTextField; Public classPrizedrawImplementsactionlistener{JTextField randomNum1;//global variable, random number 1JTextField randomNum2;//global variable, random number 2JButton Prizedraw;//Draw ButtonPrizedraw () {font font=NewFont ("Song Body", font.plain,15);//FontJFrame frame =NewJFrame ("lottery Program");//Create WindowJPanel P1=NewJPanel ();//Creating a Panel 1JPanel P2=NewJPanel ();//Creating a panel 2JLabel Label1=NewJLabel ("Number of rows:");//Label 1Label1.setfont (font); Label1.setforeground (Color.Blue);//Set Button ColorRandomNum1=NewJTextField (10);//Input BoxJLabel Label2=NewJLabel ("Number of digits:");        Label2.setfont (font); Label2.setforeground (Color.Blue);//Set Button ColorrandomNum2=NewJTextField (10); Prizedraw=NewJButton ("Sweepstakes");//Query buttonPrizedraw.setfont (font);                        Prizedraw.setforeground (Color.Blue); Prizedraw.addactionlistener ( This); //adding components to a panel 1P1.add (Label1);        P1.add (RANDOMNUM1);        P1.add (Label2);        P1.add (RANDOMNUM2);                P1.add (Prizedraw); JTextArea Getarea=NewJTextArea (20,45);//Multi-line text input boxGetarea.seteditable (false);//set multi-line text input box properties to read-only//Add a multiline text input box to a panel 2P2.add (Getarea); //Add a panel to the window and set the layout to BorderLayoutFrame.add ("North", p1); Frame.add ("Center", p2); Frame.setbackground (Color.lightgray);//Set Background colorframe.setresizable (false);//Settings window can not change sizeframe.setvisible (true);//Setting VisibilityFrame.pack ();//resizing windows automaticallyFrame.setsize (510,400);;//Set Window Size    }         Public voidactionperformed (ActionEvent e) {Random rom=NewRandom (); if(E.getsource () = =Prizedraw) {Randomnum1.settext (Rom.nextint (9) +1+ ""); Randomnum2.settext (Rom.nextint (9) +1+ ""); }    }         Public Static voidMain (string[] args) {Prizedraw pw=NewPrizedraw (); }}

Java Draw Small Program

Related Article

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.