Launching the Application
Step-by-step instructrions on how to launch the application
Concurrency and Thread management are woven into Java applications in order to make the application more efficient or provide additional functionality. In this chapter, we will apply the concurrency concepts we learned in the previous chapter to the implementation of an AWT and Swing based Graphical User Interface (GUI) that will allow users to view a slide show of Fruit objects stored in an ArrayList. Additional facets of Java GUI application such as the applet life cycle, Layout management, and the look-and-feel Customization will be introduced. We will also take a look at a basic optimization technique that consists of using the java.lang.StringBuffer class to append to strings and modify strings in order to avoid creating too many String instances.
- Create a new class named ShowFruits.java using File -> New File in Netbeans 5.5 MySamples project.
- Replace the new file's content with that of ShowFruits.java.
- Click on Build -> Compile "ShowFruits.java" or hit the F9 key to compile the file.
- Make sure that you still have copies of fruits.txt, watermelon.PNG, apple.PNG, orange.PNG, and banana.PNG on your computer. The image files (*.PNG) should be copied into a single directory.
- Additionally, copy the file noimage.PNG (an image to display if a fruit image is not available) into the same directory as the other image files.
- Open the fruits.txt file using notepad and change the first line of the file to reflect the full path to the fruit image files. Do not add a file separator symbol ("\") at the end of the path.
- Click on Run File -> Run "ShowFruits.java".
- A "Select Input File" window should pop up. Select the fruits.txt file and click 'open'.
Screenshot 7a: File Dialog
- You have launched the application. You should be able to see a slideshow of the fruits and their images. Try adding your own fruits and images to an input file of the prescribed format and then running the class. The new slideshow will reflect these additions.
Screenshot 7b: Show Fruits Applet
- Use the 'Applet' Menu to start, stop and otherwise test the application. Click on File -> Quit or use the close button to stop the application. Messages that indicate the name of the thread executing the method that corresponds to your action will be displayed in the bottom window of NetBeans 5.5.