Methods and steps for Java Learning GUI and its panel settings

Source: Internet
Author: User

Java Sun Existing two sets of GUI class library:

The original AWT (which is built on the platform's local graphics system, is not perfect across the platform) and a new GUI called Java base class (JFC) or swing (flexible cross-platform use);

Create a gui:1 selection container; 2 set layout mode; 3 Add components.

JPanel class: Also a container it differs from the JFrame class container in that it lacks jframe headings and borders;

JTextField class: A component that contains a single line of text data items;

Jradiobutton class: For radio buttons, this class instance generates actions and project events;

JComboBox class: For combo boxes, contains a drop-down list;

BorderLayout class: Layout management uses, from left to right, from top to bottom of the way to place parts.

Second, Java GUI panel settings, the use of methods and panel steps:

Import javax.swing.*
Import java.awt.*
Import java.awt.event.*
public class hehe {
JButton JB Utton1,jbutton2;
JLabel Jlabel1,jlabel2;
//Panel panel1,panel2,panel3;    
Public JPanel hehe1 () {
JPanel panel1=new JPanel ();
Jlabel1=new JLabel ("No one can replace you!", Jlabel.center);
Panel1.add (JLABEL1);
return Panel1;       
}
Public JPanel hehe2 () {
JPanel panel2=new JPanel ();
Jlabel2=new JLabel ("I love you!", Jlabel.center);
Panel2.add (JLABEL2);
return Panel2;      

}
Public JPanel hehe3 () {
JPanel panel3=new JPanel ();
Jbutton1=new JButton ("OK?");
Jbutton2=new JButton ("Love Me!");
Panel3.add (JButton1);
Panel3.add (JButton2);
return Panel3;    
}

public static void Main (string[] args) {
JFrame frame=new JFrame ("Dsfnkjlsdfoi");
Hehe yang=new hehe ();
JPanel panel1=yang.hehe1 ();
JPanel panel2=yang.hehe2 ();
   JPanel Panel3=yang.hehe3 ();
Frame.add (Panel1,borderlayout.north);
Frame.add (Panel2,borderlayout.center);
Frame.add (Panel3,borderlayout.south);
Frame.setdefaultcloseoperation (jframe.exit_on_close);
Frame.setsize (300,250);
Frame.setvisible (TRUE);
}
}

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.