문제

Ok - so this is my first time working with applets. I want to convert this program to an applet. I have fixed (commented out) items not needed for an applet and my final step is to replace the EXIT button to a RESET button. Is there something glaring that is missing here?

Errors

> PropertyTax99.java:43: error: cannot find symbol
>         ResetHandler rbHandler = new ResetHandler();
>         ^   symbol:   class ResetHandler   location: class PropertyTax99 PropertyTax99.java:43: error: cannot find symbol
>         ResetHandler rbHandler = new ResetHandler();
>                                      ^   symbol:   class ResetHandler   location: class PropertyTax99 PropertyTax99.java:93: error: cannot
> find symbol
>             reset();
>             ^   symbol:   method reset()   location: class PropertyTax99.resetHandler 3 errors

Code

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JApplet;

public class PropertyTax99 extends JFrame
{
    // set parameters to define extent of the window
    //changed width to 500 since the words were getting cut off
    private static final int WIDTH = 500, HEIGHT = 300; 

    //Declare and initialize 6 JLabels
        JLabel assessL = new JLabel("Assessment Home Value: ", SwingConstants.RIGHT);
        JLabel schoolTaxL = new JLabel("Decimal Value of School Tax Rate: ", SwingConstants.RIGHT);
        JLabel countyTaxL = new JLabel("Decimal Value of County Tax Rate: ", SwingConstants.RIGHT);
        JLabel totalSchoolTaxL = new JLabel("School Taxes: ", SwingConstants.RIGHT);
        JLabel totalCountyTaxL = new JLabel("County Taxes: ", SwingConstants.RIGHT);
        JLabel totalTaxesL = new JLabel("Total Taxes: ", SwingConstants.RIGHT);

    //Declate and initialize 5 JTextFields
        JTextField assessTF = new JTextField(10);
        JTextField schoolrateTF = new JTextField(10);
        JTextField countyrateTF = new JTextField(10);
        JTextField schooltaxTF = new JTextField(10);
        JTextField countytaxTF = new JTextField(10);
        JTextField totaltaxTF = new JTextField(10);

    //Declare and initialize reset button       
        JButton reset = new JButton("Reset");
        ResetHandler rbHandler = new ResetHandler();



    //Declare and initialize Calculate button
        JButton calculate = new JButton("Calculate"); 
        CalculateHandler cbHandler = new CalculateHandler();


    public PropertyTax99()
    {
    //Declare and initialize a container
        Container pane = getContentPane();
    //Set the container layout
        pane.setLayout(new GridLayout(7,2));
    //Set GUI objects in the container
        pane.add(assessL);
        pane.add(assessTF);
        pane.add(schoolTaxL);
        pane.add(schoolrateTF);
        pane.add(countyTaxL);
        pane.add(countyrateTF);
        pane.add(totalSchoolTaxL);
        pane.add(schooltaxTF);
        pane.add(totalCountyTaxL);
        pane.add(countytaxTF);
        pane.add(totalTaxesL);   
        pane.add(totaltaxTF);
        pane.add(reset);
        pane.add(calculate);

    // set title, size and visibility aspects of window
        //setTitle("Calculation of Property Taxes");
        //setSize(WIDTH, HEIGHT);
        //setVisible(true);
        //setDefaultCloseOperation(EXIT_ON_CLOSE);

    //reset Button
        reset.addActionListener(rbHandler);

    //Calculate Button
        calculate.addActionListener(cbHandler);  

    }

    //Handler for reset
    public class resetHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            reset();
        }
    }

    //Handler for calculate
    public class CalculateHandler implements ActionListener
    {

        public void actionPerformed(ActionEvent e)
        {
            double countyRate, schoolRate, assessment, schoolTax, countyTax, totalTax;      
            assessment = Double.parseDouble(assessTF.getText());
            schoolRate = Double.parseDouble(schoolrateTF.getText());
            countyRate = Double.parseDouble(countyrateTF.getText());
            schoolTax = assessment * schoolRate * .01;
            countyTax = assessment * countyRate * .01;
            totalTax = schoolTax + countyTax;
            schooltaxTF.setText(""+ String.format("%.2f", schoolTax));
            countytaxTF.setText(""+ String.format("%.2f", countyTax));
            totaltaxTF.setText(""+ String.format("%.2f", totalTax));
        }

    }

    public void init()
    {
    // main program to invoke constructor
    PropertyTax99 proptax = new PropertyTax99();
    }
}
도움이 되었습니까?

해결책

You have two basic problems...

One

You declare you rbHandler using...

ResetHandler rbHandler = new ResetHandler();

But your ResetHandler is actually declared as

public class resetHandler implements ActionListener {

Not the differences in names. Change the class declaration to public class ResetHandler implements ActionListener {

Two

There is no reset method declared anywhere in your code.

FYI: Applets shouldn't be creating frames. If you really want to make the program portable, move the core UI to a JPanel and simply add that to either a JFrame or JApplet as required

다른 팁

I see you have a class called ResetHandler which implements ActionListener.

In the actionPerformed method you have invoked a method called reset();. But where did you declare the method ?

Another issue is with the line ResetHandler rbHandler = new ResetHandler(); The r in the class name is in small case, so it would be

resetHandler rbHandler = new resetHandler();

Finally I want to show you how to debug the issues : The line

class ResetHandler location: class PropertyTax99 PropertyTax99.java:43: error: cannot find symbol ResetHandler rbHandler = new ResetHandler();

Tell us that something is wrong with the line. Java cannot find any object named ResetHandler.

cannot find symbol reset();symbol: method reset() location: class

Tells us that somethin is wrong with the line "reset();" java cannot find any such method.

PropertyTax99.resetHandler

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top