关闭小程序窗口。
因为写这个程序,我电脑上现在有N多不能关闭的小程序窗口,除了重新启动,我应该怎样关闭它们?
package applet;
import java.awt.*;
import java.awt.event.*;
public class MyTextArea extends Frame implements TextListener {
static Frame fr=new Frame("My new window!Superb!");
TextArea ta1,ta2;
public MyTextArea(){
  setBounds(0,0,200,160);
  String str1="Come on,boy!";
  String str2="What a sunny day today!";
  ta1=new TextArea(str1,10,6,TextArea.SCROLLBARS_VERTICAL_ONLY);
  ta2=new TextArea(str2,10,6,TextArea.SCROLLBARS_HORIZONTAL_ONLY);
  setLayout(new FlowLayout(FlowLayout.LEFT));
  ta1.addTextListener(this);
  ta2.setEditable(false);
  add(ta1);
  add(ta2);
  setVisible(true);
}public  void textValueChanged(TextEvent e){
  ta2.setText(ta1.getText());
}
public static void  main(String args[]){
  new MyTextArea();
  
  fr.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    System.exit(0);
   }
  }
  );
  
}}

解决方案 »

  1.   

    你既然是继承的 FREME 怎么还新创建一个 NEW FREME()对象呢
    代码应该这样:
    import java.awt.*;
    import java.awt.event.*;public class MyTextArea extends Frame implements TextListener {
    //static Frame fr = new Frame("My   new   window!Superb! ");
    TextArea ta1, ta2; public MyTextArea() {
    //对自己的类对象设置属性,而不是你的 static Frame fr = new Frame("My   new   window!Superb! ") 对象
    this.setTitle("My   new   window!Superb! ");
    setBounds(0, 0, 200, 160);
    String str1 = "Come   on,boy! ";
    String str2 = "What   a   sunny   day   today! ";
    ta1 = new TextArea(str1, 10, 6, TextArea.SCROLLBARS_VERTICAL_ONLY);
    ta2 = new TextArea(str2, 10, 6, TextArea.SCROLLBARS_HORIZONTAL_ONLY);
    setLayout(new FlowLayout(FlowLayout.LEFT));
    ta1.addTextListener(this);
    ta2.setEditable(false);
    add(ta1);
    add(ta2);
    //监听应该在设置属性的时候就一起设置完全
    this.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    });
    this.setVisible(true);
    }

    public void textValueChanged(TextEvent e) {
    ta2.setText(ta1.getText());
    } public static void main(String args[]) {
    new MyTextArea();
    }}