因为我用JFrame创建窗口的类,和JButton监听事件处理的类不在同一个类,无法使用this.dispose()所以请问一下,跨类如何使用dispose()或者setVisible(false)关闭前一个窗口?具体代码如下:
public class enterWindow extends JFrame {
enterWindow(String title){
super(title); //窗口组件代码
.........
JButton enterButton = new JButton("登陆");
buttonPanel.add(enterButton);
enterButton.addActionListener(
new Command(Command.button_enter));
.........
setVisible(true);
}
}class Command implements ActionListener {
static final int button_enter = 9; Command(int button){
curButton = button;
}
public void actionPerformed(ActionEvent e){
switch(curButton){
case button_enter:
funtionWindow fWindow = new funtionWindow("..");
break;
}
}
}过程就是点击“登陆”按钮,创建一个新的窗口!请问如何关闭前面的登陆窗口?(“登陆窗口”和“事件处理”是两个分开了类~)
谢谢!
public class enterWindow extends JFrame {
enterWindow(String title){
super(title); //窗口组件代码
.........
JButton enterButton = new JButton("登陆");
buttonPanel.add(enterButton);
enterButton.addActionListener(
new Command(Command.button_enter));
.........
setVisible(true);
}
}class Command implements ActionListener {
static final int button_enter = 9; Command(int button){
curButton = button;
}
public void actionPerformed(ActionEvent e){
switch(curButton){
case button_enter:
funtionWindow fWindow = new funtionWindow("..");
break;
}
}
}过程就是点击“登陆”按钮,创建一个新的窗口!请问如何关闭前面的登陆窗口?(“登陆窗口”和“事件处理”是两个分开了类~)
谢谢!
解决方案 »
- 这个this何解?
- 新手问个问题~~~~
- java中,对象==null,怎么可以调用它的setId(),getId(),toString等方法??见鬼了!!!
- 快速求解线程问题
- 发送InstallAnywhere 6 Enterprise 注册号
- 用java可不可以开发硬件驱动程序
- 关于增量录入数据的问题,在线等候
- 还是读文件的问题!
- 如何获得enumeration的元素的个数,除了用nextElement?
- 怎样在文本文件中追加内容?
- 服务器连接成功、只是服务器端不接收文件内容、一直等待Socket dataSocket = serverDataSocket.accept();
- 如何用java自带的加密解密,JCE
JButton enterButton = new JButton("登陆");
buttonPanel.add(enterButton);
enterButton.addActionListener(
new Command(Command.button_enter,this));//修改构造函数
.........class Command implements ActionListener {
static final int button_enter = 9;
JFrame jFrame;
Command(int button,JFrame jFrame){
curButton = button;
this.jFrame = jFrame;
}
public void actionPerformed(ActionEvent e){
switch(curButton){
case button_enter:
jFrame.dispose(); //关闭
funtionWindow fWindow = new funtionWindow("..");
break;
}
}
}