Manipulating the Screen
| [Previous] [Main] [Next] |
Manipulating the Screen
|
Item 1 points at the whole screen. There is a lot going on behind this screen so we will look at it in parts.
|
|
The screen is a JFrame component. We are going to look at how the JFrame is used in this application.
|
|
· | Inheriting from your own JxFrame - Pluggable Look and Feel
|
· | I18N - Internationalzing the code - I18N
|
· | Accessibility - Setting up the application to help handicapped users - Assistive Technology
|
· | Size Placement of window on screen (and remembering last time)
|
· | Make your screen "garbage collectible" when it closes
|
· | Logging activities and errors using the Java logging API.
|
· | Saving and Restoring user preferences using the Java Preferences API.
|
· | Item 2 - Closing the window with the upper right hand corner "x"
|
· | Item 3 - Setting the border
|
· | Item 11 - setting the screen icon
|
· | Item 12 - setting the screen title
|
· | Generating a JUnit TestCase program to test the GUI
|
|
The first step is to declare the JxFrame.
|
The JxFrame needs to be declared outside your inner methods. This is also where programmers usually set up the title for the screen (item 12). The reason the JxFrame is declared outside an inner class is that we will set a windowsActionListener to see when the windows closes. When it does the JxFrame object is set to null. If the JxFrame object you create is declared in an inner class, your WindowsActionListener will not be able to set it to null. Setting it to null, releases all of the components in the frame and makes them available for garbage collection. This listener needs to be outside the class. In the example shown, the window listener is in the main class that runs the class. If you called this screen from a menu, the declaration and window listener would be in that calling class. JxFrame code
|
|
Next you instantiate the object and set up size, location and a listener.
|
In this case we create the JxFrame object in the main class. If you called this screen from another class (such as a menu in a large application), you would declare the object in that class.
|
|
You set up the default size of the window and its location on the user's screen outside the class as well. The Java Preferences API is used to store the location and size of each panel when the user exits the panel. The next time the panel is instantiated, the last location and size is "remembered."
|
|
In this case we are setting the window's behavior when it closes to "DO_NOTHING_ON_CLOSE". The reason is to allow us to have a listener inside the class that checks to see if any edits will be lost if a close is honored. This allows us to ask the user if he or she really wants to close the window and lose all their changes. If they still want to close the window, a HIDE() and DISPOSE() are executed and the window closes. At that point the listener outside the class sees that the window is closed and sets the whole object to null.
|
|
Finally, in the class, you set the frame's icon, border and set up a listener.
|
|
Once the Frame has been instantiated (using the properties of the JxFrame version of JFrame), the icon is set (see SetIcon.class), the border is set and the internal listener is set up.
|
|
Here are the code references for these actions.
|
|
Item 1 - Pass JxFrame into Class - JxFrame Example - Pass JxFrame into class
|
Item 1 - Set JxFrame to a local variable - JxFrame Example - Set Passed in JxFrame to a local field in class
|
Item 1 - Pass JXFrame into a dialog - JxFrame Example - Example of passing frame into a JDialog
|
Item 1 - Set up size and location of JxFrame - JxFrame Example - JxFrame Setup - size and location on screen
|
item 1 - Declaration of fields so it can be used by an inside class - JxFrame Example - JxFrame Declaration for inside class - variable that are not declared global for a class cannot be seen inside inner classes. This means that if we want a window listener to set the instantiation of our class to null when it is closed, we need to have the instantiation made to a global variable.
|
|
Item 1- Window listener in the main application to set this JxFrame to null when the JxFrame is closed - JxFrame Example - JxFrame Window Listener in main (set to null when done)
|
|
Item 2 - Let user close the window - JxFrame Example - JxFrame Windows Listener in Class - check if leaving class is okay
|
Item 2 - Let user close the Frame Cancel Button- JxFrame Example - Let user close the frame
|
|
Item 3- Includes for borders - JxFrame Example - includes for borders
|
Item 3- Declaration of border variables - JxFrame Example - Declaration of border variables
|
Item 3- Setting the border - JxFrame Example - setting the JxFrame border
|
|
Item 11 Set Coffee cup to your own icon - JxFrame Example - replace coffee cup icon on frame |
|
Item 13 - Declarations and Setting Titles - JxFrame Example - JxFrame Declaration & Setting Title
|
|
|