0

我一直在关注Dietel的Java如何编程,即使我逐字复制程序并尝试导入(Ctrl-Shift-O),它仍然无法将ButtonHandler识别为一种类型。这是我的代码:

import java.awt.FlowLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;


public class ButtonTest1 extends JFrame{
private JButton plainB;
private JButton fancyB;

public ButtonTest1(){ //Constructer
    super("Testing buttons");
    setLayout(new FlowLayout());

    plainB = new JButton("Plain Button");
    add(plainB); //Add to frame

    Icon bug1 = new ImageIcon(getClass().getResource("bug1.png"));
    Icon bug2 = new ImageIcon(getClass().getResource("bug1.png"));
    fancyB = new JButton ("Fancy Button", bug1); //set image
    fancyB.setRolloverIcon(bug1); //set rollover image
    add(fancyB);

    ButtonHandler handler = new ButtonHandler(); // <--- errors are here
    fancyB.addActionListener(handler);

    }
}
4

2 回答 2

2

我认为您有人实施了ButtonHandler课程。它不是来自 Swing 库

改用ActionListener或创建自定义:

public class ButtonHandler implements ActionListener{
  ...
}
于 2013-09-12T08:16:57.907 回答
1

ButtonHandler 不是标准的摇摆类。如果您知道它的功能,您需要获取它的源代码或自行制作。你知道这是来自哪个库吗?

于 2013-09-12T08:16:24.260 回答