Stefanie Miller
CPS 406
Assignment #3





Description

Create an applet that contains a user interface with at least two components and at least one nested Layout.

I have decided to create a graphing applet. This applet will have a set of controls that the user may interact with. The controls will include the following:

  1. A Choice Box containing functions to be graphed
  2. A Graph Button that will graph the selected function in the choice box
  3. A Text Field that will allow the user to input a zoom factor
  4. A Zoom In Button that will allow the user to zoom in on the graph by the zoom factor
  5. A Zoom Out Button that will allow the user to zoom out on the graph by the zoom factor

The selected function will be graphed in blue on the Graph at the center of the applet. The range of values on the x-axis will also be displayed to give the user a point of reference.

Description of Algorithm

The ui class consists of methods and 5 variables. It will extend the Applet class and implement the ActionListener interface.

public class ui extends Applet implements ActionListener {

   protected int    selectedFunction; 
   protected int    zoomFactor;   
   protected Graph  ga;        
   protected Choice pulldownList;
   protected TextField zoomField;
   public void init ();
   public void update (Graphics g);
   public void actionPerformed (ActionEvent e);  
}
The integer selectedFunction contains the index to the selected function in the choice box once the Graph button has been clicked. The integer zoomFactor contains the factor typed into the text field next to the Zoom In button once either the Zoom In or Zoom Out buttons have been pressed. The member variables ga, pulldownList, and zoomField are all components of the applet.

The init() method sets the user interface up by placing all of the components into the correct layouts and setting the listeners for the components. The update() method simply calls the Graph ga's paint method to draw the graph on the canvas. The actionPerformed method listens for the button pushes by the user and reacts accordingly. If the Graph button is pushed, the selectedFunction variable is updated and the Graph ga is told to repaint. If either the Zoom In or Zoom Out buttons are pressed, then the zoomFactor variable is updated if necessary and the Graph ga is zoomed in upon and then told to repaint.

Links

Directions to run code

To compile the source code, compile ui.java and Graph.java, with a jdk 1.1.8 compiler. For instance at the prompt, type:


carver% /usr/npac/jdk1.1.8/bin/javac ui.java

After compiling, load the result.html applet in either a web browser or appletviewer. For instance, type:

appletviewer
http://class-server.npac.syr.edu:3768/cps406fall99-docs/ca99sam/hw3/result.html




Please send questions or comments to samill03@syr.edu.

Home