You job in this lab is write a prototype Grapher. Allow the user to enter up to 10 ints in a TextField. After each is entered, display all the values entered so far in your Grapher. Draw and label the two axis. Use OutlinedFilledCircles for the points (as demo'ed in class; feel free to name them GraphCircles or some such). Store the values entered in an ArrayList<Integer>. Assume all values are between 0 and 100.
Here's a hint that will make your task simpler. Instead of using numbers everywhere
(for the drawLines, drawStrings, and where are the data circles), use variables.
Like this:
That way you can let the machine do the arithmetic, and, if you decide to change the size
of the Frame, there's only one number to change instead of ALL of them!
int width=400; // assuming your Frame is 500x500
int top=50; // the top of the graph (i.e. where 100 goes)
int bottom=top+width; // the bottom of the graph (where 0 goes)
int left=50; // left edge, where the y-axis goes
int right=left+400;
int x = 0;)
for (Integer nextInt: list) {
x += width/10; // to move over 1/10 the width
GraphCircle theCircle = new GraphCircle();
theCircle.setX(x);
int y=some formula using nextInt; (bottom - nextInt.intValue()*width/100?)
theCircle.setY(y);
theCircle.paint(g);
}
You could also store GraphCircles. Each time the Grapher is sent a number
to store, it converts it to a GraphCircle and stores that (use an ArrayList<GraphCircle>).
This makes it simple to draw points, and complicated to store each input (instead of vice-versa;
you can't get something for nothing!).