话不多说直接上代码
import java.awt.*;
import java.awt.color.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.*;
public class LoginF extends JFrame{
LoginF()//构造方法
{
setVisible(true);
setBackground(Color.blue);
setSize(700,700);
setLocation(200,70);
xxxxx xx=new xxxxx();
this.addWindowListener(xx);//委托监听器
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new LoginF();//对象
}
}
class xxxxx implements WindowListener//窗口监听器
{//为什么只用一个方法而搞那么多方法,因为接口必须要实现全部的哦
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e)
{
System.exit(-1);
}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}
By the way,swing的JFrame是可以直接点击关闭的。
再见互联网的广大朋友们。