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:
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.
The ui class consists of methods and 5 variables. It will extend the
Applet class and implement the ActionListener interface.
The
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.
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.
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.javaAfter 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