Suggested Projects


Skill-Building Exercises

  1. Practice with Inner Classes:   Solve the problem of the dangling reference by rewriting ListeningMainFrame2 using the field-level inner class design approach.

  2. The Existing Class Design:   Rewrite ListeningMainFrame6 to use itself as the EventListener (existing class design) instead of using an anonymous class.

  3. Handling the KeyEvent:   Extend ListeningMainFrame7 to register an additional KeyListener with the textarea. This KeyListener should popup a JOptionPane asking if the user needs help when the user “types” Ctrl-H.

  4. Exploring the Complexity of the Event-Handling Framework:   Write a single listener class that implements all the Listeners that can be registered with a JMenuItem. Implement each method to print the name of the method to the console. Extend ListeningMainFrame0 and register this listener with menuItem1 using all the appropriate registration methods. Compile and run the application. Select the menu items and see what is printed to the console. Because this will be a sizable class, I recommend using one of the external class design approaches.

  5. Thinking for Yourself:   Write an application that displays a frame. When the user clicks the close box of the frame, the application should ask the user if he’s sure he wants to quit and offer two options: “Yes” and “No”. Only quit the application if the user responds “yes”. Hint: the source object will be the frame.

  6. Querying the Event:   Write a MouseListener that prints a message to the console when the user releases the left mouse button, but only if it has been pressed for at least five seconds. Extend ListeningMainFrame0 and register this listener with the JList.

  7. Venturing Deeper Into the API:   Imagine that the visible area of ListeningMainFrame0’s textArea is divided into 4 equal quadrants. Keep in mind that textArea is contained by a JScrollPane and therefore, its visible area is quite different than its bounds. Extend ListeningMainFrame0 to print a message to the console saying which quadrant was clicked each time the mouse is clicked in the textArea.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

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