请看代码,菜单栏的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);
}}
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);
}}
解决方案 »
- DES解密是报错,请解。。。
- 求好心人帮忙解决hibernate问题
- 大家有人见过这个错误提示吗?5555555555555希望大家说说啊。或者指引一条处理这个问题的方法啊55谢谢
- JMF播放音乐问题
- java怎样从SQL Server数据库的image字段读取然后下载成文件?
- 有关JAVA的数据库操作
- 照抄书上代码报错: 不是抽象的,并且未覆盖 java.awt.event.KeyListener 中的抽象方法KeyReleased
- JBuilder各版本的区别是什么?5、6、7???
- 各位节日快乐!节后见!建议大家把贴子该结的都结一结吧!
- Java基础,循环输出打印九九乘法表
- 看的一本书上代码,问题见注释
- 关于值传递和引用传递的区别
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "three.class"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>
{
public void WindowClosing(WindowEvent e)
{System.exit(0);}
});把上面的WindowClosing改成windowClosing窗口关闭按钮就有效了!exit和close按钮我运行都是有效的,我用的是eclipse
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
或者是加入代码
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);