Java form basic operation statement JFrame, basic operation jframe

Source: Internet
Author: User

Java form basic operation statement JFrame, basic operation jframe

Package com. swift; import java. awt. color; import java. awt. gridLayout; import java. util. random; import javax. swing. JFrame; import javax. swing. JPanel; public class RP_Frame extends JFrame {private static final long serialVersionUID = 1L; public RP_Frame () {setBounds (200,200,500,300 ); // set the form size position setTitle ("basic operation statement of Java form"); // set the Form title JPanel pnBasic = new JPanel (); // generate a large canvas setContentPane (pnBasic); // put it in the form pnBa Sic. setLayout (new GridLayout (,); // The canvas is arranged in a grid of two rows and one column. The row and column are separated by five pixels. // JPanel pnGreen = new JPanel (); // regenerate a small green canvas // JPanel pnYellow = new JPanel (); // regenerate a small yellow canvas // pnYellow. setBackground (Color. YELLOW); // set the color of the canvas // pnGreen. setBackground (Color. GREEN); // set the color of the canvas // pnBasic. add (pnYellow); // pnBasic. add (pnGreen); for (int I = 0; I <(4*3); I ++) {JPanel pn = new JPanel (); // generate multiple small canvas Random ran = new Random (); int red = ran. nextInt (2 56); int yellow = ran. nextInt (256); int blue = ran. nextInt (256); pn. setBackground (new Color (red, yellow, blue); // set the random Color pnBasic for the canvas. add (pn); // put it into the large canvas} // final JButton btn = new JButton (); // btn. setText ("too many broken button too many"); // setContentPane (btn); // btn. addActionListener (new ActionListener () {// @ Override // public void actionreceivmed (ActionEvent e) {// Random ran = new Random (); // int index = ran. nextIn T (101); // System. out. println ("Hello! "+ Index); // btn. setText ("variable" + index); //}); 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_Frame ();}}

 

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.