Week 8 Exercises

  1. Write a simple class called Message with a single public method that brings up a modal dialog with a user specified string message. The box should have a single button with the label "OK". When the button is pressed, the box is dismissed. This class should have a single static, public method with this signature:

    public static void alert(String message, Frame parent)
    
    Use a layout manager of your choice to give the dialog a pleasing appearance.

    Revise the payroll applet from Class 6 so that an alert is displayed if the user enters a pay rate less than the minimum wage ($5.25 an hour).

  2. To the Message class add an okCancel() method similar to the last exercise with this signature:

    public static boolean alert(String message, Frame parent)
    
    This method should return true if the user presses the OK Button and false if they press the Cancel button. To the extent possible, there should be no other public methods in this class. (Methods you override from superclasses may have to be declared public.) Use a layout manager of your choice to give the dialog a pleasing appearance.

    Revise the payroll applet from Class 6 so that an alert is displayed if the user enters a pay rate less than the minimum wage ($5.25 an hour). If the user presses OK, the applet will calculate the total pay. Otherwise, it won't.

  3. To the same Message class add a third method that brings up a query dialog that has a TextField to allow the user to enter a single line of text, then returns the line of text. The method should have the following signature:

    public static String query(String question, Frame parent)
    
    The method should return whatever the user types in the box. To the extent possible, there should be no other public methods in this class. Use a layout manager of your choice to give the dialog a pleasing appearance.

    Revise the payroll applet from Class 6 so that if the user enters a pay rate less than the minimum wage ($5.25 an hour) or an incorrect pay rate (e.g. "Five dollars and 25 cents") the applet puts up a dialog asking for a new rate.

All three exercises must be handed in. You should hand in a cover sheet with your name, email address, URLs where the three applets can be found, and source code for each class. You should also provide screen shots of the applet running just in case the grader has trouble connecting to your web site.


Previous | Top
Last Modified October 28, 1999
Copyright 1997-1999 Elliotte Rusty Harold
elharo@metalab.unc.edu