33. Advanced Java Database Programming

 
[Page 1003]

Programming Exercises

Sections 29.2 “29.3

29.1* ( Creating an investment value calculator ) Write a program that calculates the future value of an investment at a given interest rate for a specified number of years . The formula for the calculation is as follows :
 futureValue = investmentAmount x (1 + monthlyInterestRate)  yearsx12  

Use text fields for interest rate, investment amount, and years. Display the future amount in a text field when the user clicks the Calculate button or chooses Calculate from the Operation menu (see Figure 29.24). Show a message dialog box when the user clicks the About menu item from the Help menu.

Figure 29.24. The user enters the investment amount, years, and interest rate to compute future value.


29.2* ( Using popup menus ) Modify Listing 29.1, MenuDemo.java, to create a popup menu that contains the menus Operations and Exit, as shown in Figure 29.25. The popup is displayed when you click the right-mouse button on the panel that contains the labels and the text fields.
Figure 29.25. The popup menu contains the commands to perform arithmetic operations.

Sections 29.4 “29.5

29.3** ( A paint utility ) Write a program that emulates a paint utility. Your program should enable the user to choose options and draw shapes or get characters from the keyboard based on the selected options (see Figure 29.26). The options are displayed in a tool bar. To draw a line, the user first clicks the line icon in the tool bar and then uses the mouse to draw a line in the same way you would draw using Microsoft Paint.
[Page 1004]
Figure 29.26. This exercise produces a prototype drawing utility that enables you to draw lines, rectangles, ovals, and characters.


29.4* ( Using actions ) Write a program that contains the menu items and tool bar buttons that can be used to select flags to be displayed in an ImageViewer , as shown in Figure 29.27. Use the Action interface to centralize the processing for the actions.
Figure 29.27. The menu items and tool buttons are used to display selected images in the ImageViewer .


Sections 29.6 “29.10

29.5* ( Demonstrating JOptionPane ) Write a program that creates option panes of all types, as shown in Figure 29.28. Each menu item invokes a static show Xxx Dialog method to display a dialog box.
Figure 29.28. You can display a dialog box by clicking a menu item.

29.6* ( Creating custom dialog ) Write a program that creates a custom dialog box to gather user information, as shown in Figure 29.29.
[Page 1005]
Figure 29.29. The custom dialog box prompts the user to enter username and password.


29.7* ( Using JFileChooser ) Write a program that enables the user to select a file from a file open dialog box. A file open dialog box is displayed when the Browse button is clicked, as shown in Figure 29.30. The file is displayed in the text area, and the filename is displayed in the text field when the OK button is clicked in the file open dialog box. You can also enter the filename in the text field and press the Enter key to display the file in the text area.
Figure 29.30. The program enables the user to view a file by selecting it from a file open dialog box.


29.8* ( Selecting an audio file ) Write a program that selects an audio file using the file dialog box, and use three buttons, Play, Loop, and Stop, to control the audio, as shown in Figure 29.31. If you click the Play button, the audio file is played once. If you click the Loop button, the audio file keeps playing repeatedly. If you click the Stop button, the playing stops. The selected audio files are stored in the folder named audio under the exercise directory.
Figure 29.31. The program allows you to choose an audio file from a dialog box and use the buttons to play, repeatedly play, or stop the audio.


[Page 1006]
29.9** ( Playing TicTacToe with a computer ) The game in §16.7, "Case Study: TicTacToe," facilitates two players. Write a new game that enables a player to play against the computer. Add a File menu with two items, New Game and Exit, as shown in Figure 29.32. When you click New Game, it displays a dialog box. From this dialog box, you can decide whether to let the computer go first.
Figure 29.32. The new TicTacToe game enables you to play against the computer.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net