I just started learning Swing programming, see Java Guide, made some notes. Maybe some old, everyone should not yell me!
This is our first SWING running effect:
This is the code I knocked in the guide:
Package test;
Import javax.swing. *;
Public class helloworldswing {
Public static void createandshowgui () {
Jframe.SetDefault (TRUE);
JFrame Frame = New JFrame; "Test");
Frame.setDefaultCloseOperation (jframe.exit_on_close);
Jlabel label = new Jlabel ("Hello World Swing.");
Frame.getContentPane (). Add (label);
Frame.PACK ();
Frame.setVisible (TRUE);
}
Public static void main (String [] args) {
Swingutilities.invokelater (new runnable () {
Public void run () {
CreateandShowgui ();
}
});
}
}
I don't understand ^ _ ^.
Then read the following:
This program demonstrates four parts that have all Swing programs:
1. Import the relevant package (dizzy, who doesn't know?);
2, set a top container (this I also know! I have seen it in various graphical interface programs.);
3, show this container;
4, manage threads.
Nothing is new, just feel that this thing creates a window than MFC.
Most Swing procedures also need to import two AWT packages:
Import java.awt. *; import java.awt.event. *;
There are three top Swing containers: JFrame, JDIALOG, and JAPPLET.
Among them, Jframe.SetDefault (TRUE); only for 1.4 or later versions.
All SWING components are inherited from JComponent.
Note that Jlabel is in the Content of JFrame, except Menu and Form Decorations must be in the content of the form (and MFC).
Looking forward to 1.5 will have improved.
In the previous program, replacing setFaultCloseOperation (jframe.exit_on_close); the line of code will be:
Frame.addwindowlistener (new windowadapter () {public void window {system.exit (0);}});
Yes, this is much more.
Finally, thread safety management.
555, just start? There is no interest in interest. When Sun can make your tutorial more attractive (almost dry drain and a boring text. Is this still doing?)?