Swing, as an "enhanced version" of the AWT component, was created primarily to overcome the problem that the AWT-built GUI was not universally available on all platforms. Allowing programmers to specify a unified GUI display style across platforms is also the biggest advantage of swing. Swing is an addition to AWT, not a replacement.
The following are the hierarchies and inheritance relationships for swing packages.
Javax.swingclass JComponent
-
-
All implemented Interfaces:
-
ImageObserver, Menucontainer, Serializable
-
-
Direct known subclasses:
-
-
AbstractButton, Basicinternalframetitlepane, Box, Box.filler, JColorChooser, JComboBox, JFileChooser, JInternalFrame, Jinternalframe.jdesktopicon, JLabel, Jlayer, JLayeredPane, JList, JMenuBar, Joptionpane,jpanel, JPopupMenu, JProgressBar, JRootPane, Jscrollbar, JScrollPane, Jseparator, JSlider, JSpinner, JSplitPane, JTabbedPane, JTable, Jtableheader, JTextComponent, JToolBar, JToolTip, JTree,
JViewport
-
-
There are two main types of swing containers, the window and Panel,window windows are divided into two types: JFrame (Form) and JDialog (dialog), the Panel panel has two types: JPanel panel and JScrollPane (with scroll bar). JPanel must be put into a top-level container such as JFrame, which can be said to be jpanel for a more elaborate layout.
-
Programmatic implementation steps for Windows:
1. Inheriting JFrame class (JDialog Class)
2. Instantiate a JFrame object (JDialog object) and call the Getcontentpane () method to convert the form into a container;
3, set the parameters of the object (form size, etc.), set the closing method (if not set, the default is Windows General shutdown mode), complete the implementation of the window.
Below, let's look at a simple example.
public class Jlayout extends jframe{
public void Createjframe (String title) {
JFrame jf=new JFrame (title);//Instantiate a Form object
Container Ct=jf.getcontentpane ();//Convert a form into a container
JLabel jl=new JLabel ("jframe form Example");//
Jl.sethorizontalalignment (swingconstants.center);//Set the alignment of the label text
Ct.add (JL);//Add a label to the container
Ct.setbackground (Color.White);//Set Background color
Ct.setlayout (NULL);
Jf.setvisible (TRUE);
Jf.setsize (200, 150);//Set size
Jf.setdefaultcloseoperation (Windowconstants.exit_on_close);
JButton bt=new JButton ("point Me");//define a button
Bt.sethorizontalalignment (Swingconstants.center);
Bt.setbounds (10, 10, 100, 21);
Bt.addactionlistener (new ActionListener () {//(new Actionlinstener () {
public void actionperformed (ActionEvent e) {
New Jd (Jlayout.this). setvisible (True);
}
});
Ct.add (BT);
}
Class Jd extends jdialog{
Public Jd (Jlayout frame) {
Super (Frame, "dialog box", true);
Container Ct=getcontentpane ();
Ct.add (New JLabel ("Let you order It"));
SetBounds (120,120,100,100);
}
}
public static void Main (String args[]) {
New Jlayout (). Createjframe ("");
}
}
-
Swing Programming Overview