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。如果我的按钮不起作用我就不能继续写作
答案 0 :(得分:0)
更改
private class AddBButtonListener implements ActionListener{
到
private class DrawButtonListener implements ActionListener{