importjava.awt.FlowLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;publicclassAextendsJFram...
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class A extends JFrame{
public void main(String[] args){
JFrame frame = new A();
frame.setTitle("测试内部类");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(220, 80);
frame.setVisible(true);
}
A(){
JButton jbtOK = new JButton("OK");
setLayout(new FlowLayout());
add(jbtOK);
ActionListener listener = new OKListener();
jbtOK.addActionListener(listener);
}
private class OKListener implements ActionListener{
public void actionPerformed(ActionEvent e){
System.out.println("It is OK");
}
}
}
问题:
(1)为什么 public void actionPerformed(ActionEvent e)中 public 不能省?
(2)“private class OKListener implements ActionListener 中 private 不能省是因为:监听器类在框架类外是不能被应用程序使用的” 这句话什么意思?
(3)为什么即使这两个都加了,程序也没有别的错误了,可是还是不能运行??
*/
展开