Package com.swing;
Import java.awt.*;
Import javax.swing.*;
public class SWING01 extends jframe{
/**
* 1. What is Swing
* Swing is the ui--of the Java platform and it acts as a software that handles all interactions between users and computers. It actually acts as an intermediary between the user and the computer.
*
* 2.Swing Bag
* Java.lang.Object--->java.awt.component-->java.awt.container-->java.swing.jcomponent
*
* 3. Components
* 1.JFrame
JFrame is the main window, which is tied to the status of Jdialog,japplet. However, a jframe can add JDialog and japplet into its content panel, which in turn cannot
2.JLabel
JLabel is a label. Embed HTML tags in its text to easily implement a hyperlink component
3.JButton
JButton is a button. It's as simple as JLabel.
4.JTextField
A text box
5.JTextArea
The text area, unlike the text box, is multi-line
6.JPasswordField
7.JPanel
A panel. Typically used as a layout for control components.
8.JCheckBox
check box
9.JRadioButton
Radio button. The radio button is used to Buttongroup. A radio button added to the same buttongroup indicates that only one of them is selectable between them. The selection of radio buttons in different buttongroup is not affected.
Wait http://blog.csdn.net/xxkkff/article/details/1489572 This has introduction, can see
*
*/
Create the first form inheritance extends JFrame
public void Createjframe (String title)
{
JFrame jf=new JFrame (title); Define a Jfrom object title is the name of the form
Get a container
Container Container=jf.getcontentpane (); Put labels inside the container
Create a jlable label
JLabel ji=new JLabel ("This is a jframe form");
is the contents of the label centered
Ji.sethorizontalalignment (Swingconstants.center);
Add a label to a container
Container.add (JI);
Set the color of the container
Container.setbackground (Color.White);
To set the visualization of a form
Jf.setvisible (TRUE);
Set the size of a form
Jf.setsize (200,150);
Set the closing time for a form
Jf.setdefaultcloseoperation (Windowconstants.hide_on_close);
/**
* Exit_on_close: Indicates exit application default window closed
* Dispose_on_close: You can close the window without doing anything
* Hide_on_close: Indicates that the default window for hidden Windows is closed
*
*/
}
public static void Main (string[] args) {
New Swing01 (). Createjframe ("first form");
}
}
Java Basics-----Swing