importjavax.swing.JButton;importjavax.swing.JFrame;publicclassTestMyFrameextendsJFrame{privateJButtonlogin=newJButton("login");publicTestMyFrame(){Actionaction=newAction(...
import javax.swing.JButton;
import javax.swing.JFrame;
public class TestMyFrame extends JFrame
{
private JButton login = new JButton("login");
public TestMyFrame()
{
Action action = new Action();
login.addActionListener(action);
this.add(login);
this.setBounds(50,50,50,50);
this.setVisible(true);
}
public static void main(String[] args)
{
new TestMyFrame();
}
}
下面是事件监听器类
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Action implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dispose();
}
}
为什么我不能在那个事件监听器类里面使用dispose()方法关闭 那个Jframe框架? 我应该怎么做?
异常处理信息:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
The method dispose() is undefined for the type Action
at Action.actionPerformed(Action.java:11)
展开