Character calculator JFrame form software edition JPanel JTextField JTextArea JButtton JLabel setContentPane,

Source: Internet
Author: User

Character calculator JFrame form software edition JPanel JTextField JTextArea JButtton JLabel setContentPane,

Import java. awt. borderLayout; import java. awt. color; import java. awt. gridLayout; import java. awt. event. actionEvent; import java. awt. event. actionListener; import java. util. random; import javax. swing. JButton; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. JPanel; import javax. swing. JTextField; public class RP_Frame2 extends JFrame {private static final long serialVersionUID = 1L; publ Ic RP_Frame2 () {setBounds (200,200,500,300); // set the form size position setTitle ("character calculator"); // set the Form title JPanel pnBasic = new JPanel (); // generate a large canvas setContentPane (pnBasic); // place it in the form pnBasic. setLayout (new GridLayout (2, 1); // The canvas is arranged in a grid of two rows and one column. The interval between rows and columns is 5 pixels. JPanel pnGreen = new JPanel (); // regenerate a small green canvas JPanel pnYellow = new JPanel (); // regenerate a small yellow canvas pnYellow. setBackground (Color. YELLOW); // specifies the canvas color pnGreen. setBackground (Color. GREEN );// Canvas color pnBasic. add (pnYellow); pnBasic. add (pnGreen); // add a label to the green canvas below as the output JLabel result = new JLabel (); pnGreen. add (result); result. setText ("enter the name and click" test character "to view the character value! "); // Re-layout pnYellow on the yellow canvas above. setLayout (new BorderLayout (); JLabel label = new JLabel (); // generate a label. setText ("input name"); pnYellow. add (label, BorderLayout. WEST); // place it in the label on the left of the Yellow canvas. setBackground (Color. YELLOW); JTextField text = new JTextField (15); // generate a text box with a length of 15. setBackground (Color. YELLOW); pnYellow. add (text, BorderLayout. CENTER); JButton btn = new JButton (); // generate button btn. setBackground (Color. YELLOW); pnYellow. add (btn, BorderLayout. EAST); // place it in the btn on the right of the Yellow canvas. setText ("test character"); btn. addActionListener (new ActionListener () {@ Override public void actionreceivmed (ActionEvent e) {Random ran = new Random (); int index = ran. nextInt (101); if (index> = 90) {result. setText (text. getText () + "your character value is" + index + "grade:" + "");} else if (index> = 80) {result. setText (text. getText () + "your character value is" + index + "grade:" + "Daniel");} else if (index> = 60) {result. setText (text. getText () + "your character value is" + index + "grade:" + "");} else if (index> = 40) {result. setText (text. getText () + "your character value is" + index + "grade:" + "codeph");} else if (index> = 20) {result. setText (text. getText () + "your character value is" + index + "grade:" + "Code");} else {result. setText (text. getText () + "your character value is" + index + "grade:" + "") ;}}); setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); // sets the program to stop running setVisible (true) when the form is closed; // sets the form to be visible, otherwise nothing will be displayed} public static void main (String [] args) {new RP_Frame2 ();}}

 

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.