package com.trackwar;
import java.awt.*;
import java.awt.event.*;
public class TrackClient extends Frame {
public void paint(Graphics g) {
Color c=g.getColor();
g.setColor(Color.RED);
g.fillOval(50,50, 30, 30);
}
public void lauchFrame(){
this.setLocation(400, 300);
this.setSize(800, 600);

this.addWindowFocusListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}

});
this.setResizable(false);
this.setVisible(true);
this.setTitle("TrackWar");
this.setBackground(Color.GREEN);
}

public static void main(String[] args) {
TrackClient tc=new TrackClient();
tc.lauchFrame(); }}
劳烦大家看下,为什么此程序运行完关闭不了???

解决方案 »

  1.   

    点的哪个?  是X么?import javax.swing.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;public class Test extends JPanel {private JFrame frame = null;public Test() {
    frame = new JFrame(-#34;Test-#34;);frame.getContentPane().add(this);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    int option = JOptionPane.showConfirmDialog(null,-#34;是否完全退出该系统?-#34;,-#34;系统提示-#34;,JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
    if (option == JOptionPane.YES_OPTION)
    System.exit(0);
    }
    });
    frame.setSize(300, 200);
    frame.setVisible(true);
    }public static void main(String[] args) {
    new Test();
    }
    }