出错了!!
程序:import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class myWindow extends Frame implements ActionListener
{
MenuBar mb;
myDialog myd;
Menu menu1;
MenuItem mt1,mt2;
myDialog(String s)
{
super(s);
setLayout(new GridLayout(1,1));
setSize(160,170);
setBackground(Color.white);
setVisible(false);
mb=new MenuBar();
menu1=new Menu("对话框操作");
mt1=new MenuItem("打开对话框");
mt2=new MenuItem("关闭对话框");
mt1.addActionListener(this);
mt2.addActionListener(this);
menu1.add(mt1); menu1.add(mt2);
mb.add(menu1); setMenuBar(mb);
myd=new myDialog(this,"求积框",false);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==mt1)
myd.setVisible(true);
else if(e.getSource()==mt2)
myd.setVisible(false);
}
}
class myDialog extends Dialog implements ActionListener
{
Button but;
TextField text1,text2,text3;
Label lab1,lab2,lab3;
GridLayout gl;
myDialog(Frame f,String s,boolean b)
{
super(f,s,b);
but=new Button("确定");
text1=new TextField(10);
text2=new TextField(10);
text3=new TextField(10);
lab1=new Label("输入被乘数");
lab2=new Label("输入乘数");
lab3=new Label("乘积");
gl=new GridLayout(3,2);
setLayout(gl); setSize(200,100);
setVisible(false); setModal(false);
add(lab1); add(lab2); add(lab3);
add(text1); add(text2); add(text3);
add(but);
but.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
double d;
if(e.getSource()==but)
{
double i,j;
i=Double.valueOf(text1.getText()).doubleValue();
j=Double.valueOf(text2.getText()).doubleValue();
d=i*j;
text3.setText(String.valueOf(d));
}
}
}
public class E21 extends Applet implements ActionListener
{
myWindow win;
Button but1,but2;
public void init()
{
win=new myWindow("我的窗口");
but1=new Button("打开窗口");
but1=new Button("关闭窗口");
add(but1); add(but2);
but1.addActionListener(this);
but2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSourse()==but1)
win.setVisible(true);
else if(e.getSourse()==but2)
win.setVisible(false);
}
}
运行的结果:
--------------------配置: <默认>--------------------
E:\java\E21java.java:10: invalid method declaration; return type required
myDialog(String s)
^
1 error
处理已完成。