简单问题---怎么关闭不了? setDefaultCloseOperation(3);加上这句试试! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以代码贴出来吗?这样很难找到问题所在的,如果不方便的话,可以发email, [email protected] to shihb():我用的是awt,好象你说的那个东东不能通过编译. 下面是代码:import java.awt.*;public class my3 extends Frame{ public static void main(String args[]) { my3 frame1=new my3(); frame1.setSize(200,200); frame1.setTitle("stand a label object"); Label label1=new Label("this is a label object"); Font font=new Font("Serif",Font.ITALIC|Font.BOLD,20); label1.setFont(font); frame1.add(label1); frame1.setVisible(true); }} import java.awt.*;import java.awt.event.*;public class Frametest extends Frame{ public Frametest(String title) { super(title); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public static void main (String args[]) { Frametest test=new Frametest("This is title"); test.setLocation(100,100); test.setSize(300,300); test.setVisible(true); }} 在 myframe中添加下面的方法protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e);}你必须对你的窗体的关闭事件进行处理,这样才能关闭上面的这个方法就是说让系统自己去处理,就自动关闭了如果你要想在关闭前做一些事情就可以这样protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if(e.getID() == WindowEvent.WINDOW_CLOSING) { //要处理的代码 }} 哦,原来你继承的是Frame那我这个也不一定能行了如果你把你的程序该成extends JFrame我的就没问题了 我觉得有两种办法,一种是在你的frame中加一个“退出”button,其中有System.exit(0);即可!另一种办法就是让frame上的关闭button有效。也就是在frame定义的地方加上:setDefaultCloseOperation(3);其中“3”就是使button有效的参数。你是不是位置放的不对? 你的程序中应该是:frame1.setDefaultCloseOperation(3); CanFly(我会飞)的方法应该是对的!还有其他方法,但是大同小异了! 对JTree的操作 java写QQ斗地主记牌器 for 请问各位大大们,javax.swing.JOptionPane具体应该怎么使用?? 关于JDK5.0中的线程控制问题 java新人请教入门的学习方法 那位高手知道如何获得ClassLoader的搜索类的路径? 简单问题----数据类型转换 关于处理待审核FAQ的办法,请各位给出自认为有价值的待审核FAQ,包括所属子版! SCJD需要培训吗? 请教大家JAVA入门该看哪本书?装什么软件? 在股票分析模拟系统中关于选择无状态的Session Bean or有状态的Session Bean 还是实体Bean的问题
import java.awt.*;
public class my3 extends Frame
{
public static void main(String args[])
{
my3 frame1=new my3();
frame1.setSize(200,200);
frame1.setTitle("stand a label object");
Label label1=new Label("this is a label object");
Font font=new Font("Serif",Font.ITALIC|Font.BOLD,20);
label1.setFont(font);
frame1.add(label1);
frame1.setVisible(true);
}
}
import java.awt.event.*;
public class Frametest extends Frame
{
public Frametest(String title)
{
super(title);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public static void main (String args[])
{
Frametest test=new Frametest("This is title");
test.setLocation(100,100);
test.setSize(300,300);
test.setVisible(true);
}
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
}
你必须对你的窗体的关闭事件进行处理,这样才能关闭
上面的这个方法就是说让系统自己去处理,就自动关闭了
如果你要想在关闭前做一些事情就可以这样
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if(e.getID() == WindowEvent.WINDOW_CLOSING) {
//要处理的代码
}
}
那我这个也不一定能行了
如果你把你的程序该成extends JFrame
我的就没问题了
另一种办法就是让frame上的关闭button有效。也就是在frame定义的地方加上:
setDefaultCloseOperation(3);
其中“3”就是使button有效的参数。你是不是位置放的不对?
frame1.setDefaultCloseOperation(3);
还有其他方法,但是大同小异了!