Java Reference
In-Depth Information
The for loop in lines 12-14 changes the size of the window and moves its upper-left cor-
ner with each iteration. The window grows from 10
400 as the loop
progresses. You can close the window and application by pressing Ctrl+C on your key-
board.
×
10 in size to 400
×
Displaying a Splash Page
The lack of adornment on a JWindow component makes it suitable for use as a splash
page , a graphic or text that displays as an application loads.
Java 6 adds a better, faster way to do this by defining a graphic that functions as an
application's splash. The graphic loads even before the Java interpreter and disappears
when the application begins running.
9
The graphic can be specified with the -splash attribute when the class is run at a com-
mand line. Here's how to do it with the SimpleWindow class:
java -splash:lighthouse.jpg SimpleWindow
If you need a graphic to test this capability, download lighthouse.
jpg , a photograph of a Norwegian lighthouse taken by Steve
Cadman, from the Day 9 page of this topic's website at http://
www.java21days.com.
NOTE
Another technique to define a splash graphic is covered on Day 14, “Developing Swing
Applications.”
Creating a Component
Creating a graphical user interface is a great way to get experience working with objects
in Java because each interface component is represented by its own class.
To use an interface component in Java, you create an object of that component's class.
You already have worked with the container classes JFrame and JWindow .
One of the simplest components to employ is JButton , the class that represents clickable
buttons.
In most programs, buttons trigger an action—click Install to begin installing software,
click a smiley button to begin a new game of Minesweeper, click the Minimize button to
prevent your boss from seeing Minesweeper running, and so on.
A Swing button can feature a text label, a graphical icon, or a combination of both.
Search WWH ::




Custom Search