【问题标题】:cannot find symbol when creating new action listener创建新的动作监听器时找不到符号
【发布时间】:2013-11-16 15:20:10
【问题描述】:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DrawLinesAgain extends JFrame{
    JPanel
        panel;
    JButton
        addB,
        drawB;
    JTextField
        tx,          //x cordinate
        ty;          //y cordinate
    JLabel
        lDirections, //explain what to do
        lx,          //"enter x value"
        ly;          //"enter y value"

    public void DrawLines(){
        setTitle("Draw Lines");
        setSize(400,400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        buildPanel();
        add(panel);
        setVisible(true);
    }

    private void buildPanel(){  
    //labels
        lDirections = new JLabel("Add some points to the que and draw a picture");
        lx = new JLabel("X: ");
        ly = new JLabel("Y: ");
    //textFields
        tx = new JTextField(5);
        ty = new JTextField(5);
    //buttons
        addB = new JButton("Add Point");
        addB.addActionListener(new AddBButtonListener());
        drawB = new JButton("Draw!");
        drawB.addActionListener(new DrawBButtonListener());
    }

    private class AddBButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            System.out.println("finally???");
        }


    }
}

当我尝试编译时,它给了我错误:

DrawLinesAgain.java:42: error: cannot find symbol
    drawB.addActionListener(new DrawBButtonListener());
                                ^
symbol:   class DrawBButtonListener
location: class DrawLinesAgain

我不知道出了什么问题,请帮忙。显然我还没有完成这个程序。我只是不知道如何将 ActionListener 添加到 JButton。如果我的按钮不起作用,我真的不能继续写了

【问题讨论】:

  • 你的 DrawBButtonListener 类在哪里? ...

标签: java swing jbutton actionlistener


【解决方案1】:

改变

private class AddBButtonListener implements ActionListener{

private class DrawButtonListener implements ActionListener{

【讨论】:

    猜你喜欢
    • 2012-11-21
    • 2014-10-13
    • 2021-07-02
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 2012-05-20
    • 2013-12-24
    相关资源
    最近更新 更多