请看代码,菜单栏的exit按钮无效,close按钮无效,窗口的关闭按钮无效,why???import java.awt.*;
import java.applet.*;
import java.awt.event.*;
class mainwindow extends Frame implements ActionListener
{
TextField t1,t2;
Button b1,b2;
MenuBar mb1;Menu m1;
MenuItem mi;
mainwindow(String s,int a,int b)
{
    super(s);
    mb1 =new MenuBar();
    m1=new Menu("file");
    mi=new MenuItem("exit");
    t1 =new TextField(10);
    t2=new TextField(10);
    b1 =new Button("ok");
    b2 =new Button("close");
    b1.addActionListener(this);
    t2.setEditable(false);
    setSize(a,b);
    setVisible(true);
    setBackground(Color.blue);
    setLayout(new GridLayout(1,3));
    
    mb1.add(m1);m1.add(mi);
    mi.addActionListener(this);
    add(t1);add(t2);add(b1);add(b2);
    b1.addActionListener(this);
    b2.addActionListener(this);
    setMenuBar(mb1);
    
    addWindowListener(new WindowAdapter()
                        {
                           public void WindowClosing(WindowEvent e)
                              {System.exit(0);}
                         });     pack();
}

public void actionPerformed(ActionEvent e)
{
if ((e.getSource()==b1) && (t1.getText().equals("pig")))
    {t2.setText("猪");}
else if((e.getSource()==b1)&&(t1.getText().equals("dog")))
    {t2.setText("狗");}
else if((e.getSource()==b1)&&(t1.getText().equals("cat")))
    {t2.setText("猫");}
    
if(e.getSource()==b2)
    {System.exit(0);}
    
if(e.getSource()==mi)
    {System.exit(0);}    
}
}


public class three extends Applet
{
mainwindow mywindow;

public void init()
{
   mywindow =new mainwindow("mywindow",60,300);
   
}}

解决方案 »

  1.   

    补充,html代码为:<html>
    <head>
    </head>
    <body bgcolor="000000">
    <center>
    <applet
    code = "three.class"
    width = "500"
    height = "300"
    >
    </applet>
    </center>
    </body>
    </html>
      

  2.   

    addWindowListener(new WindowAdapter()
      {
      public void WindowClosing(WindowEvent e)
      {System.exit(0);}
      });把上面的WindowClosing改成windowClosing窗口关闭按钮就有效了!exit和close按钮我运行都是有效的,我用的是eclipse
      

  3.   

    加入代码
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      

  4.   

    重写方法名字错了..........windowClosing
    或者是加入代码
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      

  5.   

    EXT的关闭要自己来实现的。不实现的话是没有做任何事情的。