java 关闭窗口代码要写在哪里?
我要加一个关闭窗口的addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){...
我要加一个关闭窗口的addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
这段要插在下面的哪里?还要改哪里?import java.awt.*;
class FrmApp
{
static Frame fra=new Frame("窗口");
public static void main(String args[])
{
fra.setSize(250,150);
fra.setLocation(100,200);
fra.setVisible(true);
System.out.println("State:"+fra.getState());
System.out.println("Title:"+fra.getTitle());
System.out.println("Visible:"+fra.isVisible()); }
} 展开
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
这段要插在下面的哪里?还要改哪里?import java.awt.*;
class FrmApp
{
static Frame fra=new Frame("窗口");
public static void main(String args[])
{
fra.setSize(250,150);
fra.setLocation(100,200);
fra.setVisible(true);
System.out.println("State:"+fra.getState());
System.out.println("Title:"+fra.getTitle());
System.out.println("Visible:"+fra.isVisible()); }
} 展开
4个回答
2013-08-14
展开全部
addWindowListener是Frame类继承下来的方法,直接在对象中添加,我帮你把代码写完整了。=========================================================================import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
class FrmApp
{
static Frame fra=new Frame("窗口");
public static void main(String args[])
{
fra.setSize(250,150);
fra.setLocation(100,200);
fra.setVisible(true);
fra.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});System.out.println("State:"+fra.getState());
System.out.println("Title:"+fra.getTitle());
System.out.println("Visible:"+fra.isVisible());}
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
class FrmApp
{
static Frame fra=new Frame("窗口");
public static void main(String args[])
{
fra.setSize(250,150);
fra.setLocation(100,200);
fra.setVisible(true);
fra.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});System.out.println("State:"+fra.getState());
System.out.println("Title:"+fra.getTitle());
System.out.println("Visible:"+fra.isVisible());}
展开全部
你用的 swing 吗?加上 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
或者加上窗口事件监听器:
addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent we) {
dispose();
}
});
或者加上窗口事件监听器:
addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent we) {
dispose();
}
});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-14
展开全部
import java.awt.*;
class FrmApp
{public FrmApp(){static Frame fra=new Frame("窗口");fra.setSize(250,150);
fra.setLocation(100,200);
fra.setVisible(true);
System.out.println("State:"+fra.getState());
System.out.println("Title:"+fra.getTitle());
System.out.println("Visible:"+fra.isVisible()); fra.addWindowListener(new WinClose());}
public static void main(String args[])
{new FrmApp();
} class WinClose implements WindowListener{public void windowClosing(WindowEvent e);{System.exit(0);}public void windowOpened(WindowEvent e);{}public void windowActivated(WindowEvent e);{}public void windowDeactivated(WindowEvent e);{}public void windowClosed(WindowEvent e);{}public void windowIconified(WindowEvent e);{}public void windowDeiconified(WindowEvent e);{}}
}
class FrmApp
{public FrmApp(){static Frame fra=new Frame("窗口");fra.setSize(250,150);
fra.setLocation(100,200);
fra.setVisible(true);
System.out.println("State:"+fra.getState());
System.out.println("Title:"+fra.getTitle());
System.out.println("Visible:"+fra.isVisible()); fra.addWindowListener(new WinClose());}
public static void main(String args[])
{new FrmApp();
} class WinClose implements WindowListener{public void windowClosing(WindowEvent e);{System.exit(0);}public void windowOpened(WindowEvent e);{}public void windowActivated(WindowEvent e);{}public void windowDeactivated(WindowEvent e);{}public void windowClosed(WindowEvent e);{}public void windowIconified(WindowEvent e);{}public void windowDeiconified(WindowEvent e);{}}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-14
展开全部
在 【System.out.println("Visible:"+fra.isVisible());】的前面写frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询