Character Calculator JFrame form Software edition JPanel JTextField jtextarea Jbuttton JLabel Setcontentpane

Source: Internet
Author: User

Importjava.awt.BorderLayout;ImportJava.awt.Color;Importjava.awt.GridLayout;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.JTextField; Public classRp_frame2extendsJFrame {Private Static Final LongSerialversionuid = 1L;  Publicrp_frame2 () {setbounds (200, 200, 500, 300);//set the form size positionSettitle ("character calculator");//set the form titleJPanel Pnbasic=NewJPanel ();//Create a large canvasSetcontentpane (Pnbasic);//put in a formPnbasic.setlayout (NewGridLayout (2, 1));//Canvas follows a grid layout of two rows and rows and columns spaced 5 pixelsJPanel Pngreen =NewJPanel ();//recycled into a little green canvasJPanel Pnyellow =NewJPanel ();//into a little yellow canvas .Pnyellow.setbackground (Color.yellow);//Canvas Setting ColorPngreen.setbackground (Color.green);//Canvas Setting ColorPnbasic.add (Pnyellow);        Pnbasic.add (Pngreen); //the bottom row of the green canvas adds labels as outputJLabel result =NewJLabel ();        Pngreen.add (result); Result.settext (After entering the name, click on the ' Test character ' button to see the character value! "); //top row Yellow canvas re-layoutPnyellow.setlayout (NewBorderLayout ()); JLabel label=NewJLabel ();//Generate LabelsLabel.settext ("Enter Name"); Pnyellow.add (label, borderlayout.west);//put it on the left side of the yellow canvasLabel.setbackground (Color.yellow); JTextField text=NewJTextField (15);//Generate a text box of length 15Text.setbackground (Color.yellow);        Pnyellow.add (text, borderlayout.center); JButton btn=NewJButton ();//Generate buttonBtn.setbackground (Color.yellow); Pnyellow.add (BTN, borderlayout.east);//put it on the right side of the yellow canvasBtn.settext ("Test character"); Btn.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {Random ran=NewRandom (); intindex = Ran.nextint (101); if(Index >= 90) {Result.settext (Text.gettext ()+ "Your character value is" + Index + "level" + "Great God"); } Else if(Index >= 80) {Result.settext (Text.gettext ()+ "Your character value is" + Index + "level" + "Daniel"); } Else if(Index >= 60) {Result.settext (Text.gettext ()+ "Your character value is" + Index + "level" + "program Ape"); } Else if(Index >= 40) {Result.settext (Text.gettext ()+ "Your character value is" + Index + "rank" + "code Farm"); } Else if(Index >= 20) {Result.settext (Text.gettext ()+ "Your character value is" + Index + "rank" + "code Animal"); } Else{Result.settext (Text.gettext ()+ "Your character value is" + Index + "level" + "rookie");        }            }        }); Setdefaultcloseoperation (jframe.exit_on_close);//set the program to stop running when the form is closedSetVisible (true);//The Settings form is visible, otherwise nothing will be displayed    }     Public Static voidMain (string[] args) {Newrp_frame2 (); }}

Character Calculator JFrame form Software edition JPanel JTextField jtextarea Jbuttton JLabel Setcontentpane

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.