Java is a very powerful programming language, but Java's GUI power has always been its Achilles heel. Although Java offers 2 graphics solutions, AWT and swing. However, these 2 graphics libraries are very limited in functionality, and they do not bring more user experience. And AWT and swing are slow to update. All the while to the Java SE 5 there was no noticeable change. Thankfully, Java SE 6 has finally added more power to them. With these features, the user interface designed using AWT and swing can be closer to the user. To enable readers to experience the beauty of the Java SE 6 GUI Earlier, this article discusses the main features provided by the Java SE 6 GUI.
Show startup interface
Now many commercial and non-commercial software must be initialized at startup, sometimes the initialization time will be very long, such as Photoshop, Flash and so on, in order to let users have patience to continue to wait, do not mistakenly think that the dead, these software before initialization always show a graphical interface to tell users what the software is doing. Figure 1 is the initialization interface for FLASH8 at startup.
Figure 1 The Flash8 start interface
We may also need such an interface when designing software. Of course, this can be done in earlier versions of Java SE, but it's hard, the basic implementation is to put a graphic on the form, and then show this, which requires writing some code, and Java SE 6 provides a simpler way to do this without adding a line of code, And there is no need to recompile the source program when the interface changes. Let's look at a simple example first.
import javax.swing.*;
import java.awt.*;
public class TestSplash
{
public static void main(String args[])
{
try
{
// 为了让启动界面多显示3秒,
// 如果是正常的程序,这里应该时初始化代码
Thread.sleep(3000);
JFrame frame = new JFrame("Java SE 6 启动界面演示");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("我的标签", JLabel.CENTER);
frame.add(label, BorderLayout.CENTER);
frame.setSize(300, 95);
frame.setVisible(true);
}
catch (InterruptedException e)
{}
}
}
The above program is a very simple interface demo program, its interface as shown in Figure 2.
Figure 2
If you use Java Testsplash to run the above program directly, the interface shown in Figure 2 is immediately displayed. Java SE 6 provides an option on the Java command to display a picture before displaying the main interface of the program.
java -splash:splash.gif TestSplash
If you run the above command, the Splash.gif is displayed before the interface shown in Figure 2, and then a few seconds later the splash.gif automatically closes, and then the main interface is displayed. Thread.Sleep (3000) in the above program; To make the splash.gif display longer, you can change the sentence to a straight-forward initialization code. The Splash.gif file is shown in Figure 3.
Figure 3 Splash.gif