Assignment-03

 

 

 

Foreword

Resources

Code Listings

Foil Sets

Assignments

Solutions

External Resources

SiteMap

Search

Home

Up ] Assignment-01a ] Assignment-01b ] Assignment-01c ] Assignment-01d ] Assignment-02 ] Assignment-02a ] [ Assignment-03 ] Assignment-03a ] Assignment-03b ] Assignment-03c ] Assignment-03d ] Assignment-04 ] Assignment-04a ] Assignment-04b ] Assignment-05 ] Assignment-06 ] Assignment-07 ]

Writing a Java applet with basic components,
extended to also using layouts.

We are now entering a part of the course using Java 1.1 where you need to work more with appletviewer to view your applets. So you need to have access either to a UNIX workstation cluster where you can redirect the display on osprey7 to show appletviewer on your workstation, or some other local access to JDK1.1.

When you submit your applet, link both the applet (.html file) and the source code (.java file) to your homework page. We may be able to view your applet with Explorer 4.0 or we can download your .java file and run appletviewer to grade it.

  1. You may choose to design your own applet with basic components. If so, be sure to include at least two different types of Events. For example, you may have Buttons or Textfields that generate ActionEvents, and you should also have something that generates an ItemEvent, such as a list, choice, or set of checkboxes. Add Layouts to nicely organize your components.
  2. or try the following simple calculator applet.

    Look at the example problem 10.10 on page 577 of the Deitel textbook, which shows a GUI for a calculator. For your applet create a similar GUI with the textfield at the top for the calculator display and with buttons for numbers, but pick only one operator to implement, say +. You may also want a "clear" button. Also note that since you're not using a Layout yet, your buttons may not line up like a normal calculator, but that's o.k. In addition, add a set of choiceboxes, with one checkbox group, at the bottom for different colors.

    Implement the buttons:

    Note that you need to have a variable to keep track of at least one number, the "accumulator". This is initialized by the program to 0.
    Whenever you push a number button, it appends that digit to the string in the textfield at the top.
    Whenever you push the + button, it adds the contents of the textfield as an integer (you can use parseInt) to the current contents of the "accumulator" and displays the result in the textfield.
    If you have a clear button, clear both the textfield and set the accumulator to 0.

    Also implement the choiceboxes:

    Whenever you click on a color checkbox, change the background of the applet, or the background of the buttons to that color.
    Add layouts to organize your components.