-1

I am working on a problem for school and I am having an issue with the CalculateButtonHandler. I am also using an ExitButtonHandler but that is not giving me any issues. I have tried re-reading my textbook and have searched the web. After racking my brain over this issue I can't figure out why this won't work. This is my first GUI attempt and I am sure I will have to mess with the program to get it the way I want. I only want to know how to fix this CalculateButtonHandler issues as I can work on the rest if need be. Below is the code for the project.

Issues: Lines 38, 76 and 77: CalculateButtonHandler cannot be resolved to a type.

What does this mean and how can I go about fixing it?

//This program calculates the weighted average of four test scores.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;

public class SNHU6_4 extends JFrame
{

private static final int WIDTH = 400;
private static final int LENGTH = 300;

private JLabel testscore1L;
private JLabel weight1L;
private JLabel testscore2L;
private JLabel weight2L;
private JLabel testscore3L;
private JLabel weight3L;
private JLabel testscore4L;
private JLabel weight4L;
private JLabel scoreL;

private JTextField testscore1TF;
private JTextField weight1TF;
private JTextField testscore2TF;
private JTextField weight2TF;
private JTextField testscore3TF;
private JTextField weight3TF;
private JTextField testscore4TF;
private JTextField weight4TF;
private JTextField scoreTF;

private JButton calculateB;
private JButton exitB;

private CalculateButtonHandler cbHandler;
private ExitButtonHandler ebHandler;

public SNHU6_4()
{
    //Creating the labels
    testscore1L = new JLabel ("Enter first test score: ",  SwingConstants.RIGHT);
    testscore2L = new JLabel ("Enter second test score: ", SwingConstants.RIGHT);
    testscore3L = new JLabel ("Enter third test score: ", SwingConstants.RIGHT);
    testscore4L = new JLabel ("Enter fourth test score: ", SwingConstants.RIGHT);
    weight1L = new JLabel ("Enter first test score weight : ", SwingConstants.RIGHT);
    weight2L = new JLabel ("Enter second test score weight :", SwingConstants.RIGHT);
    weight3L = new JLabel ("Enter third test score weight :", SwingConstants.RIGHT);
    weight4L = new JLabel ("Enter fourth test score weight :",     SwingConstants.RIGHT);
    scoreL = new JLabel ("Final score: ", SwingConstants.RIGHT);

    //Creating the text fields
    testscore1TF = new JTextField ("0",5);
    testscore1TF.setHorizontalAlignment(JTextField.CENTER);
    testscore2TF = new JTextField ("0",5);
    testscore1TF.setHorizontalAlignment(JTextField.CENTER);
    testscore3TF = new JTextField ("0",5);
    testscore3TF.setHorizontalAlignment(JTextField.CENTER);
    testscore4TF = new JTextField ("0",5);
    testscore4TF.setHorizontalAlignment(JTextField.CENTER);
    weight1TF = new JTextField ("0",5);
    weight1TF.setHorizontalAlignment(JTextField.CENTER);
    weight2TF = new JTextField ("0",5);
    weight2TF.setHorizontalAlignment(JTextField.CENTER);        
    weight3TF = new JTextField ("0",5);
    weight3TF.setHorizontalAlignment(JTextField.CENTER);
    weight4TF = new JTextField ("0",5);
    weight4TF.setHorizontalAlignment(JTextField.CENTER);
    scoreTF = new JTextField ("0",5);
    scoreTF.setHorizontalAlignment(JTextField.CENTER);

    //Creating the calculate button
    calculateB = new JButton("Calculate");
    cbHandler = new CalculateButtonHandler();
    calculateB.addActionListener(cbHandler);

    //Creating the exit button
    exitB = new JButton("Exit");
    ebHandler = new ExitButtonHandler();
    exitB.addActionListener(ebHandler);

    //Creating the window title
    setTitle ("Weighted Average of Test Scores");

    //Get the container
    Container pane = getContentPane();

    //Set the layout
    pane.setLayout(new GridLayout(5, 4));

    //Placing components in the pane
    pane.add(testscore1L);
    pane.add(testscore1TF);
    pane.add(testscore2L);
    pane.add(testscore2TF);
    pane.add(testscore3L);
    pane.add(testscore3TF);
    pane.add(testscore4L);
    pane.add(testscore4TF);
    pane.add(weight1L);
    pane.add(weight1TF);
    pane.add(weight2L);
    pane.add(weight2TF);
    pane.add(weight3L);
    pane.add(weight3TF);
    pane.add(weight4L);
    pane.add(weight4TF);
    pane.add(calculateB);
    pane.add(exitB);

    //Set the window size
    setSize(WIDTH, HEIGHT);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

private class CalculateButtonHanlder implements ActionListener
{
    public void actionPerformed(ActionEvent e)
    {
        double testscore1, testscore2, testscore3, testscore4;
        double weight1, weight2, weight3, weight4;
        double average1, average2, average3, average4;
        double totalAverage;

        testscore1 = Double.parseDouble(testscore1TF.getText());
        testscore2 = Double.parseDouble(testscore2TF.getText());
        testscore3 = Double.parseDouble(testscore3TF.getText());
        testscore4 = Double.parseDouble(testscore4TF.getText());

        weight1 = Double.parseDouble(weight1TF.getText());
        weight2 = Double.parseDouble(weight2TF.getText());
        weight3 = Double.parseDouble(weight3TF.getText());
        weight4 = Double.parseDouble(weight4TF.getText());

        average1 = testscore1 * weight1;
        average2 = testscore2 * weight2;
        average3 = testscore3 * weight3;
        average4 = testscore4 * weight4;

        totalAverage = average1 + average2 + average3 + average4;

        scoreTF.setText("" + String.format("%,2f", totalAverage));
    }
}

private class ExitButtonHandler implements ActionListener
{
    public void actionPerformed(ActionEvent e)
    {
        System.exit(0);
    }
}

public static void main(String[] args)
{
    SNHU6_4 rectObject = new SNHU6_4();



}

} 
  • 1
    What issues? Please read [How to ask](http://stackoverflow.com/help/how-to-ask) first, otherwise people here won't be able to help you. – Patrik Jun 17 '15 at 14:43
  • My question has been updated. – LostandConfused Jun 17 '15 at 14:54
  • Where is the class `CalculateButtonHandler` defined? Look like [here: GUI Trouble reading JTextField](http://stackoverflow.com/questions/9260723/gui-trouble-reading-jtextfield) – Patrik Jun 17 '15 at 14:56

2 Answers2

1

CalculateButtonHandler cannot be resolved to a type

Is telling you it can't find a class by that name:

private class CalculateButtonHanlder implements ActionListener

You have a typo "Hanlder"

private class CalculateButtonHandler implements ActionListener
camickr
  • 321,443
  • 19
  • 166
  • 288
0

You spelled `CalculateButtonHandler' as 'CalculateButtonHanlder' when you declared the class on line 120. Fix that and it will work.

arnbobo
  • 2,515
  • 2
  • 12
  • 18