Ok, using Jgrasp I was given a problem that asked me to design a GUI program to find the weighted average of four test scores. The four test scores and their respective weights are give in the following format....testscore1 weight1
This is what I have so far, the code will not compile. I was wondering if someone could help me with the reason as to why that is.
//Page 349 Number 1
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Page3491 extends JFrame
{
private static final int W = 400;
private static final int L = 300;
private JButton calculate, exitB;
private CalculateButtonHandler cbHandler;
private ExitButtonHandler ebHandler;
public Page3491()
{
//Labels
gradesL = new JLabel("Enter your grades: ",SwingConstants.RIGHT);
weightL = new JLabel("Your weighted averages are: ",SwingConstants.RIGHT);
//Text Fields
grade1TF = new JTextField(5);
grade2TF = new JTextField(5);
grade3TF = new JTextField(5);
grade4TF = new JTextField(5);
weight1TF= new JTextField(5);
weight2TF= new JTextField(5);
weight3TF= new JTextField(5);
weight4TF= new JTextField(5);
//Creating Calculate Button
calculateB = new JButton("Calculate");
cbhandler = new CalculateButtonHandler();
calculateB.addActionListner(ebHandler);
//Creating Exit Button
exitB = new JButton("Exit");
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
//Setting the Title of the Window
setTitle("Weighted Average Calculator");
setSize(W,L);
//Getting Container
Container pane = getContentPane();
//Setting Layout
pane.setLayout(new GridLayout(6,4));
//Placing Components in the pane
pane.add(gradesL);
pane.add(grade1TF);
pane.add(grade2TF);
pane.add(grade3TF);
pane.add(grade4TF);
pane.add(weightL);
pane.add(weight1TF);
pane.add(weight2TF);
pane.add(weight3TF);
pane.add(weight4);
pane.add(calculateB);
pane.add(exitB);
// Step 4 -- Creating Event Handlers
cbHandler = new ConvertButtonHandler();
convertB.addActionListener(cbHandler);
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
//Setting the size and displaying it
setSize(WIDTH, HEIGHT);
setVisibile(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class CalculateButtonhandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double s1, s2, s3, s4, w1, w2, w3, w4;
s1 = Double.parseDouble(grade1TF.getText());
s2 = Double.parseDouble(grade2TF.getText());
s3 = Double.parseDouble(grade3TF.getText());
s4 = Double.parseDouble(grade4TF.getText());
w1 = (s1 * .6);
w2 = (s2 * .1);
w3 = (s3 * .1);
w4 = (s4 * .2);
celTF.setText(Double.toString(c));
}
}
private class ExitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.out.println();
System.exit(0);
}
}
public static void main(String[] args)
{
Page3491 = new Page3491();
}
}
Any help is very much appreciated.