So I am having a problem with even starting to create a line graph that takes in the values given by the user. I have the code that I have so far (currently only computes the rate of growth which is part of the assignment). So what I need to do is to take all the values that the user inputs (bv1, ev_1, ev_2, ev_3, ev_4, and ev_5...), and use them to plot points on a line graph that has the amount of money on the Y-Axis, and the year on the X-Axis. For the labels of the graph I am also supposed to use HTML formatting in Java for the labels for the axes. I know I am supposed to use stuff like superpaint g, and @Override, but I am not sure where to start (some example code would help). Any help is appreciated as this assignment is due tomorrow!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.util.ArrayList;
import java.util.List;
public class Rate_Graph1 extends JApplet implements ActionListener
{
double E, B, N;
JLabel rateTitle, firstBv, ev1, ev2, ev3, ev4, ev5, returnRate;
JTextField bv1, ev_1, ev_2, ev_3, ev_4, ev_5, usersRate;
JButton calc;
public void setTop()
{
rateTitle = new JLabel("Calculate your return rate!", JLabel.CENTER);
add(rateTitle, BorderLayout.NORTH);
}
public void setMiddle()
{
firstBv = new JLabel("Enter the beginning value:");
bv1 = new JTextField("", 15);
ev1 = new JLabel("Enter the value after the first year:");
ev_1 = new JTextField("", 15);
ev2 = new JLabel("Enter the value after the second year:");
ev_2 = new JTextField("", 15);
ev3 = new JLabel("Enter the value after the third year:");
ev_3 = new JTextField("", 15);
ev4 = new JLabel("Enter the value after the fourth year:");
ev_4 = new JTextField("", 15);
ev5 = new JLabel("Enter the value after the fifth, and final year:");
ev_5 = new JTextField("", 15);
JPanel pane1 = new JPanel(new FlowLayout());
pane1.add(firstBv);
pane1.add(bv1);
pane1.add(ev1);
pane1.add(ev_1);
pane1.add(ev2);
pane1.add(ev_2);
pane1.add(ev3);
pane1.add(ev_3);
pane1.add(ev4);
pane1.add(ev_4);
pane1.add(ev5);
pane1.add(ev_5);
JPanel mainPane = new JPanel(new GridLayout(3, 1));
mainPane.add(pane1);
add(mainPane, BorderLayout.CENTER);
}
public void setBottom()
{
returnRate = new JLabel("Your return rate is:");
usersRate = new JTextField("", 15);
calc = new JButton("Calculate Rate!");
calc.addActionListener(this);
JPanel pane4 = new JPanel(new FlowLayout());
pane4.add(returnRate);
pane4.add(usersRate);
pane4.add(calc);
add(pane4, BorderLayout.SOUTH);
}
public void init()
{
setLayout(new BorderLayout());
setTop();
setMiddle();
setBottom();
}
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == calc){
E = Double.parseDouble(ev_5.getText());
B = Double.parseDouble(bv1.getText());
double rate = Math.pow(E / B, 1.0 / 5.0) - 1;
usersRate.setText(+ rate * 100 + "%");
}
}
}