-4

有任何想法吗 ?第 66 行是一个大括号,你会在下面看到它,我在下面用 // 显示它。在 Eclipse 中,它不断出现错误,并且不知道如何摆脱它。有任何想法吗?谢谢!它是在动作监听器之后写的,我忘了关闭它吗?

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

public class operation extends JFrame{
    private JTextField monday;
    private JTextField tuesday;
    private JTextField wednesday;
    private JTextField thursday;
    private JTextField friday;
    private JTextField saturday;
    private JTextField sunday;
    private JButton finalize;

    public operation(){
        super("Weekly Total Calculator");
        setLayout(new FlowLayout());

        monday = new JTextField("How much you spent Monday", 20);
        monday.setFont(new Font("Ariel", Font.PLAIN, 14));
        add(monday);

        tuesday = new JTextField("How much you spent Tuesday", 20);
        tuesday.setFont(new Font("Ariel", Font.PLAIN, 14));
        add(tuesday);

        wednesday = new JTextField("How much you spent Wednesday", 20);
        wednesday.setFont(new Font("Ariel", Font.PLAIN, 14));
        add(wednesday);

        thursday = new JTextField("How much you spent Thursday", 20);
        thursday.setFont(new Font("Ariel", Font.PLAIN, 14));
        add(thursday);

        friday = new JTextField("How much you spent Friday", 20);
        friday.setFont(new Font("Ariel", Font.PLAIN, 14));
        add(friday);

        saturday = new JTextField("How much you spent Saturday", 20);
        saturday.setFont(new Font("Ariel", Font.PLAIN, 14));
        add(saturday);

        sunday = new JTextField("How much you spent Sunday", 20);
        sunday.setFont(new Font("Ariel", Font.PLAIN, 14));
        add(sunday);

        finalize = new JButton("Calculate!");
        add(finalize);

        finalize.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent ae){

                    double mon = Double.parseDouble(monday.getText());
                    double tues = Double.parseDouble(tuesday.getText());
                    double wed = Double.parseDouble(wednesday.getText());
                    double thurs = Double.parseDouble(thursday.getText());
                    double fri = Double.parseDouble(friday.getText());
                    double sat = Double.parseDouble(saturday.getText());
                    double sun = Double.parseDouble(sunday.getText());

                    private double sum = mon + tues + wed + thurs + fri + sat + sun;

                    JOptionPane.showMessageDialog(null, "Your total is " + sum + "!", "Total", JOptionPane.PLAIN_MESSAGE);

               }
        }
        //THIS IS THE ERROR^

    }



}

请帮忙!任何想法都会奏效。我真的不知道这笔交易是什么:(

4

4 回答 4

7

您正在方法调用中创建一个匿名对象 - 确保在最后关闭方法调用:

finalize.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent ae){
           // all your stuff
       }
}); // you were missing the ");"
于 2012-08-03T01:09:13.680 回答
5

我认为问题在于您需要);在第 66 行的括号之后添加。

于 2012-08-03T01:09:19.183 回答
3

失踪”);”

finalize.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent ae){

                double mon = Double.parseDouble(monday.getText());
                double tues = Double.parseDouble(tuesday.getText());
                double wed = Double.parseDouble(wednesday.getText());
                double thurs = Double.parseDouble(thursday.getText());
                double fri = Double.parseDouble(friday.getText());
                double sat = Double.parseDouble(saturday.getText());
                double sun = Double.parseDouble(sunday.getText());

                private double sum = mon + tues + wed + thurs + fri + sat + sun;

                JOptionPane.showMessageDialog(null, "Your total is " + sum + "!", "Total", JOptionPane.PLAIN_MESSAGE);

           }
    });
于 2012-08-03T01:10:26.173 回答
1

您没有关闭用 . 打开的括号finalize.addActionListener(,并且缺少分号。

于 2012-08-03T01:09:38.907 回答