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