就是一个错误,但不明白!! 一个.java文件里面只可以有一个public class并且filename和public class name要一样才可以 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把你文件保存为ExamP152_2a.java能运行,不过你程序有问题的,什么都 没有显示出来。 一定要保证java程序名和public class的名字一致。 你的程序不太好,我帮你改进了一下。/** * <p>Title: This follow is newman's writing</p> * <p>Description: I want better writing ,instead of best one!</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: [email protected]</p> * @author Newman * @version 1.0 */import java.awt.*;import java.awt.event.*;public class ExamP152_2a{public static void main(String args[]) {mywindow F=new mywindow(); F.show(); }}class mywindow extends Frame implements ActionListener{MenuBar menubar; Areadialog areadialog1,areadialog2; Menu menu1; MenuItem item1,item2; mywindow() {super("这里是求面积的窗口"); setLayout(new GridLayout(1,1)); setSize(60,70); setVisible(false); menubar=new MenuBar(); menu1=new Menu("求积"); item1=new MenuItem("求三角形面积"); item2=new MenuItem("求圆的面积"); item1.addActionListener(this); item2.addActionListener(this); menu1.add(item1); menu1.add(item2); //added by newman menubar.add(menu1) ; this.setMenuBar(menubar); areadialog1=new Areadialog(this,"求三角形面积",false); areadialog2=new Areadialog(this,"求圆面积",false); //added by newman addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit (0);}}); } public void actionPerformed(ActionEvent e) {if(e.getSource()==item1) {areadialog1.setVisible(true); } else if(e.getSource()==item2) {areadialog2.setVisible(true); } } }class Areadialog extends Dialog implements ActionListener{Button button; TextField text1,text2,text3; Label label1,label2; GridLayout net; Areadialog(Frame F,String s,boolean p){super(F,s,p); //added by newman addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ Areadialog.this.setVisible(false);} } ); button=new Button("开始运算"); text1=new TextField(10); text2=new TextField(10); text3=new TextField(10); label1=new Label("请输入三角形的底"); label2=new Label("请输入三角形的高"); net=new GridLayout(3,2); setLayout(net); setSize(200,100); setVisible(false); setModal(false); add(label1);add(label2); add(text1);add(text2);add(text3); add(button); button.addActionListener(this); } public void actionPerformed(ActionEvent e) {double x; if(e.getSource()==button) {double a,b; a=Double.valueOf(text1.getText()).doubleValue(); b=Double.valueOf(text2.getText()).doubleValue(); x=1/2*a*b; text3.setText(String.valueOf(x)); } else { } }} newman0708你改得现在程序没有错误,可是现在不能处理圆的计算啊,三角形的是没有问题。有没有方法来实现来圆的计算啊,不过我不会写那个对话框了,不知道实现这两个方法用同一个对话框可不可以啊,(但它们要求输入的数据不同),急问。。 链表问题 请问为什么不能显示文本提示 高分求java功能 新手问题 如何利用输出流向一个文件输入一张图片,在利用输入流将其读取?? 猴子吃桃问题 同步的问题 关于Dialog线程的问题 怎样获取访问Tomcat Server的客户端的IP地址(内网地址)。 有那些Jsp的好的开源的论坛可以下? 问两个很简单的问题 请问哪里有JDK 1.4的Linux版本下载, www.javasoft.com不能下载 OutputStream 的flush() 和 write( )
* <p>Title: This follow is newman's writing</p>
* <p>Description: I want better writing ,instead of best one!</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: [email protected]</p>
* @author Newman
* @version 1.0
*/import java.awt.*;
import java.awt.event.*;public class ExamP152_2a
{public static void main(String args[])
{mywindow F=new mywindow();
F.show();
}
}class mywindow extends Frame implements ActionListener
{MenuBar menubar;
Areadialog areadialog1,areadialog2;
Menu menu1;
MenuItem item1,item2;
mywindow()
{super("这里是求面积的窗口");
setLayout(new GridLayout(1,1));
setSize(60,70);
setVisible(false);
menubar=new MenuBar();
menu1=new Menu("求积");
item1=new MenuItem("求三角形面积");
item2=new MenuItem("求圆的面积");
item1.addActionListener(this);
item2.addActionListener(this);
menu1.add(item1);
menu1.add(item2);
//added by newman
menubar.add(menu1) ;
this.setMenuBar(menubar);
areadialog1=new Areadialog(this,"求三角形面积",false);
areadialog2=new Areadialog(this,"求圆面积",false);
//added by newman
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit (0);}});
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==item1)
{areadialog1.setVisible(true);
}
else if(e.getSource()==item2)
{areadialog2.setVisible(true);
}
}
}class Areadialog extends Dialog implements ActionListener
{Button button;
TextField text1,text2,text3;
Label label1,label2;
GridLayout net;
Areadialog(Frame F,String s,boolean p)
{super(F,s,p);
//added by newman
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Areadialog.this.setVisible(false);}
}
);
button=new Button("开始运算");
text1=new TextField(10);
text2=new TextField(10);
text3=new TextField(10);
label1=new Label("请输入三角形的底");
label2=new Label("请输入三角形的高");
net=new GridLayout(3,2);
setLayout(net);
setSize(200,100);
setVisible(false);
setModal(false);
add(label1);add(label2);
add(text1);add(text2);add(text3);
add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{double x;
if(e.getSource()==button)
{double a,b;
a=Double.valueOf(text1.getText()).doubleValue();
b=Double.valueOf(text2.getText()).doubleValue();
x=1/2*a*b;
text3.setText(String.valueOf(x));
}
else
{ }
}
}
有没有方法来实现来圆的计算啊,不过我不会写那个对话框了,不知道实现这两个方法用同一个对话框可不可以啊,(但它们要求输入的数据不同),急问。。