Let's start with a Java swing Helloword program.
1 Packagecn.java.swing.chapter03;2 3 ImportJavax.swing.JButton;4 ImportJavax.swing.JFrame;5 ImportJavax.swing.JPanel;6 7 Public classDemo01 {8 9 Public Static voidMain (string[] args) {TenJFrame JFrame =NewJFrame ("Chapter03 Demo1");//creating a top-level container One AJPanel JPanel =NewJPanel ();//Creating intermediate containers - -Jframe.setcontentpane (JPanel);//The intermediate container is supported in the top-level container the -JButton button =NewJButton ("one Test button");//Create a basic component - -Jpanel.add (button);//base components are built into intermediate containers + - +Jframe.setsize (200,300);//set top level container size A atJframe.setvisible (true);//Show Top level components - - } -}View Code
Swing is roughly divided into three elements: top-level containers (JFrame), intermediate containers (JPanel), basic components (Button, Label)
Intermediate containers and basic components need to be placed in the top-level container before they are valid.
There are mainly three top-level containers in swing
1.JFrame is designed to design applications similar to Windows systems in the form of Windows
2.JDialog is similar to JFrame, except that JDialog is used to design dialog boxes
3.JApplet Java applet designed for embedding into web pages
Pending additions
Java Swing First Hello Word