Tutorial Three: Part Two
ImageFrame
To build the ImageFrame, follow these steps:
- Right-click on the
imageviewer
package in the Explorer, and select New From Template | Swing Forms | JInternalFrame. Name the new form ImageFrame. Click OK. The Form Editor will open, and the source will open (assuming your Editor window is still open from Part One) as a new tab in the Editor window.- From the Swing tab of the Component Palette, select JScrollPane, and place it on the center panel of the new form. Again from the Swing tab, select JLabel, and place it on the JScrollPane.
- Change the JLabel
variable name
to imageLabel in the Component Inspector. Set the text to an empty string, by removing the default text (jLabel1) in the Component inspector listing.- Select the top level node of the Component Inspector - ImageFrame. Scroll through the list of properties, and double-click on each of the following items to toggle the property's value from
False
toTrue
:- Lastly, we will add some code to the Editor. In the code marked
/** Initializes the Form */
towards the top of the source, modify the declaration readingpublic ImageFrame()
and add parameters so that the line readspublic ImageFrame(String imageName) {Under the
setTitle (imageName); imageLabel.setIcon (new javax.swing.ImageIcon (imageName));initComponents ();
line in this same block, add the following:The Image Viewer is now complete. Right-click on the
imageviewer
package in the Explorer, and select Compile All. Watch the status bar of the Main Window to see the progress of the compilation. Once completed, select the ImageViewer object in the Explorer, and execute it using the Execute icon on the Main Window.Use the File menu to open any GIF or JPG images you have on your local drive(s). If you don't have any images handy, browse to
$FORTE4J_HOME
/docs/Tutorial/images/
, where $FORTE4J_HOME is your Forte For Java installation directory, and select any file.You can open multiple images, resize them, iconify them, and close them.
Beginning | Prev | Next |