1
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。如果我的按钮不起作用,我真的无法继续写作

4

1 回答 1

0

改变

private class AddBButtonListener implements ActionListener{

private class DrawButtonListener implements ActionListener{
于 2013-11-25T19:50:52.853 回答