gpt4 book ai didi

java - 创建新 Action 监听器时找不到符号

转载 作者:行者123 更新时间:2023-12-01 04:12:24 25 4
gpt4 key购买 nike

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

最佳答案

改变

private class AddBButtonListener implements ActionListener{

private class DrawButtonListener implements ActionListener{

关于java - 创建新 Action 监听器时找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19794275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com