还是GUI的问题 class WindAction implements WindowListener实现了这个接口,就必须实现里面的所有方法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 java没你想象的那么厉害,呵呵 其实方法有很多,,我告诉你一种把。。不过要给我加分啊。。 :)在java里已经有一个现成的类WindowAdapter它已经空实现了WindowListener的所有的方法。。所以比想要用到它的哪个方法,就覆盖哪个方法就好了。。class WindAction extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } }} class WindAction extends WindowAdapter{ public void windowCloseing(WindowEvent e) { System.exit(0); }} //用户登陆窗体import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;import java.awt.event.WindowEvent;public class EntryFrame extends JFrame{ JLabel JLabUserName = new JLabel(); JLabel JLabUserPass = new JLabel(); JTextField JTxtUserName = new JTextField(); JTextField JTxtUserPass = new JTextField(); JButton JButEnter = new JButton(); JPanel JPan = new JPanel(); GridLayout GriLay2 = new GridLayout(3,3); GridLayout GriLay1 = new GridLayout(5,1); public EntryFrame() { JPan.setSize(100,60); JPan.setLayout(GriLay1); JLabUserName.setText("用户名:"); JLabUserName.setSize(60,20); JLabUserPass.setText("用户密码:"); JLabUserPass.setSize(60,20); JTxtUserName.setSize(60,20); JTxtUserPass.setSize(60,20); JButEnter.setSize(60,20); JPan.add(JLabUserName); JPan.add(JTxtUserName); JPan.add(JLabUserPass); JPan.add(JTxtUserPass); JPan.add(JButEnter); this.getContentPane().setLayout(GriLay2); this.setContentPane(JPan); this.addWindowFocusListener(new WindAction()); } class WindAction extends WindowAdapter { public void windowClosed(WindowEvent e) { System.exit(0); } }}//程序入口public class MainApp{ public static void main(String[] args) throws Exception { EntryFrame EF=new EntryFrame(); EF.setSize(300,200); EF.setVisible(true); }}按这样写了以后,我在主程序里实现了这个窗体后,按了X后窗体关闭的但是程序依然没有退出,怎么回事呢? 上面有个地方写错了this.addWindowListener(new WindAction());我是这样写的,问题依然存在. 不要这么复杂,内部类就不要了(仍要得话建议WindowAdapter,注意方法名的拼写)只要你的窗口是JFramesetDefaultCloseOperation(int)int HIDE_ON_CLOSE //默认,自动隐藏DISPOSE_ON_CLOSE //建议,特别是对于多窗口程序EXIT_ON_CLOSE //在单窗口中与DISPOSE_ON_CLOSE表现起来一样DO_NOTHING_ON_CLOSE //表现起来与awt一样对你按[X],alt-F4没有任何反应 !!!!急!!!! 请高手指点迷津,不甚感激!!! JLabel如何跟JRadioButton绑定 java编程思想第二版和第四版的有些什么区别?谢谢回答 [新手求助]关于窗体的问题 运行时错误 java技术交流站 群号:2303735 【关于Java UDP网络连接问题!在线等......】 如何在JBuilder 8的IDE中输入中文呀? apache+tomcat配置成功,但只有http://localhost/examples能用,为什么(shenzhipeng) EJB到底是什么东西?它能作什么? 菜鸟问题 请问JDK安装后需要设置什么?
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
}
{
public void windowCloseing(WindowEvent e)
{
System.exit(0);
}
}
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.WindowEvent;public class EntryFrame extends JFrame
{
JLabel JLabUserName = new JLabel();
JLabel JLabUserPass = new JLabel();
JTextField JTxtUserName = new JTextField();
JTextField JTxtUserPass = new JTextField();
JButton JButEnter = new JButton();
JPanel JPan = new JPanel();
GridLayout GriLay2 = new GridLayout(3,3);
GridLayout GriLay1 = new GridLayout(5,1);
public EntryFrame()
{
JPan.setSize(100,60);
JPan.setLayout(GriLay1);
JLabUserName.setText("用户名:");
JLabUserName.setSize(60,20);
JLabUserPass.setText("用户密码:");
JLabUserPass.setSize(60,20);
JTxtUserName.setSize(60,20);
JTxtUserPass.setSize(60,20);
JButEnter.setSize(60,20);
JPan.add(JLabUserName);
JPan.add(JTxtUserName);
JPan.add(JLabUserPass);
JPan.add(JTxtUserPass);
JPan.add(JButEnter);
this.getContentPane().setLayout(GriLay2);
this.setContentPane(JPan);
this.addWindowFocusListener(new WindAction());
} class WindAction extends WindowAdapter
{
public void windowClosed(WindowEvent e)
{
System.exit(0);
}
}
}//程序入口
public class MainApp
{
public static void main(String[] args) throws Exception
{
EntryFrame EF=new EntryFrame();
EF.setSize(300,200);
EF.setVisible(true);
}
}
按这样写了以后,我在主程序里实现了这个窗体后,按了X后窗体关闭的但是程序依然没有退出,怎么回事呢?
this.addWindowListener(new WindAction());
我是这样写的,问题依然存在.
只要你的窗口是JFramesetDefaultCloseOperation(int)
int
HIDE_ON_CLOSE //默认,自动隐藏
DISPOSE_ON_CLOSE //建议,特别是对于多窗口程序
EXIT_ON_CLOSE //在单窗口中与DISPOSE_ON_CLOSE表现起来一样
DO_NOTHING_ON_CLOSE //表现起来与awt一样对你按[X],alt-F4没有任何反应