I'm going to write a tutorial on a series of Java graphical interfaces. Each program tries to write only the most streamlined code needed to keep it running, so everyone can understand it.
Using the Java graphical interface requires only jdk,eclipse. If the layout abstraction is not powerful enough, it is recommended to install Jigloo First and then copy the code. (Jigloo automatically generated code redundancy is too large, put the position is not reasonable, just to see the effect, then still need to ctrl+c,ctrl+v)
To put everything in place, we need to have a jframe first. So let's talk about how to create an empty jframe.
Here is a simple example, first we need to extends JFrame, so the current class itself is a JFrame. Then create an object of the current class in the function, which is to create a jframe. The code reads from top to bottom in order.
Package Basiccompoment;import Javax.swing.jframe;import Javax.swing.windowconstants;public class EmptyJFrame extends Jframe{public static void Main (string[] args) {//now creates an object, but nothing is shown emptyjframe f = new Emptyjframe ();// With this sentence you can display a frame with only a close, minimized, maximized button, f.setvisible (TRUE);//Add this sentence to show a frame with a specified size in the upper-left corner f.setsize (300,400);// With this sentence you can put the frame in the middle of the f.setlocationrelativeto (null);//If you don't have this, the program is still in the execution state when you click Close Frame. Plus this sentence is really the release of Resources F.setdefaultcloseoperation (Windowconstants.dispose_on_close);}}
The creation of JFrame is usually placed in the Swingutilities.invokelater, as follows
Package Basiccompoment;import Javax.swing.jframe;import Javax.swing.swingutilities;import Javax.swing.windowconstants;public class EmptyJFrame2 extends Jframe{emptyjframe2 () {Initgui ();} private void Initgui () {setvisible (true); SetSize (300,400); Setlocationrelativeto (null); Setdefaultcloseoperation ( Windowconstants.dispose_on_close);} public static void Main (string[] args) {Swingutilities.invokelater (new Runnable () {public void run () {EmptyJFrame2 F = new EmptyJFrame2 ();}});}}
Java Swing simplest example (1) an empty JFrame