我一直在关注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);
}
}