dos下用javac可以编译成class文件,java运行则提示没有main,请问该怎么办?
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;public class jsq extends Applet implements ActionListener
{
int flag=0;
double x;
String s=new String("");
Panel p1,p2,p3;
Label label;
TextField text1;
Button bclear,bpoint,beq,badd,bsbb,bmult,bdiv;
Button[] b=new Button[10];
public void init()
{
p1=new Panel();p2=new Panel();p3=new Panel();
setLayout(new FlowLayout());
p1.setLayout(new FlowLayout());
p2.setLayout(new GridLayout(4,3));
p3.setLayout(new GridLayout(4,1));
label=new Label("计算器");
text1=new TextField(12);
bclear=new Button("Clear");
add(label);
p1.add(text1);p1.add(bclear);
bclear.addActionListener(this);
for(int i=0;i<10;i++)
{
b[i]=new Button(Integer.toString(i));
}bpoint=new Button(".");
beq=new Button("=");for(int i=0;i<10;i++)
{
p2.add(b[i]);
b[i].addActionListener(this);
}
p2.add(bpoint);p2.add(beq);
bpoint.addActionListener(this);
beq.addActionListener(this);
badd=new Button("+");
bsbb=new Button("-");
bmult=new Button("*");
bdiv=new Button("/");
p3.add(badd);
p3.add(bsbb);
p3.add(bmult);
p3.add(bdiv);badd.addActionListener(this);
bsbb.addActionListener(this);
bmult.addActionListener(this);
bdiv.addActionListener(this);add(p1);add(p2);add(p3);add(new Label(" "));}
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<10;i++){
if(e.getSource()==b[i]||e.getSource()==bpoint){
s=s+e.getActionCommand();
text1.setText(s);
break;
}
}if(e.getSource()==badd){
x=Double.parseDouble(s);
flag=1;
text1.setText("");
s="";
}
if(e.getSource()==bsbb){
x=Double.parseDouble(s);
flag=2;
text1.setText("");
s="";
}
if(e.getSource()==bmult){
x=Double.parseDouble(s);
flag=3;
text1.setText("");
s="";
}
if(e.getSource()==bdiv){
x=Double.parseDouble(s);
flag=4;
text1.setText("");
s="";
} if(e.getSource()==bclear){
text1.setText("");
s="";
flag=0;
}if(e.getSource()==beq){
switch(flag){
case 1:
{
x=Double.parseDouble(s)+x;
String s=String.valueOf(x);
text1.setText(s);break;
} case 2:
{
x=x-Double.parseDouble(s);
String s=String.valueOf(x);
text1.setText(s);break;
}
case 3:
{
x=Double.parseDouble(s)*x;
String s=String.valueOf(x);
text1.setText(s);break;
}
case 4:
{
if(Double.parseDouble(s)==0){text1.setText("除数不能为0!");break;}
x=x/Double.parseDouble(s);
String s=String.valueOf(x);
text1.setText(s);break;
}
}
}
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;public class jsq extends Applet implements ActionListener
{
int flag=0;
double x;
String s=new String("");
Panel p1,p2,p3;
Label label;
TextField text1;
Button bclear,bpoint,beq,badd,bsbb,bmult,bdiv;
Button[] b=new Button[10];
public void init()
{
p1=new Panel();p2=new Panel();p3=new Panel();
setLayout(new FlowLayout());
p1.setLayout(new FlowLayout());
p2.setLayout(new GridLayout(4,3));
p3.setLayout(new GridLayout(4,1));
label=new Label("计算器");
text1=new TextField(12);
bclear=new Button("Clear");
add(label);
p1.add(text1);p1.add(bclear);
bclear.addActionListener(this);
for(int i=0;i<10;i++)
{
b[i]=new Button(Integer.toString(i));
}bpoint=new Button(".");
beq=new Button("=");for(int i=0;i<10;i++)
{
p2.add(b[i]);
b[i].addActionListener(this);
}
p2.add(bpoint);p2.add(beq);
bpoint.addActionListener(this);
beq.addActionListener(this);
badd=new Button("+");
bsbb=new Button("-");
bmult=new Button("*");
bdiv=new Button("/");
p3.add(badd);
p3.add(bsbb);
p3.add(bmult);
p3.add(bdiv);badd.addActionListener(this);
bsbb.addActionListener(this);
bmult.addActionListener(this);
bdiv.addActionListener(this);add(p1);add(p2);add(p3);add(new Label(" "));}
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<10;i++){
if(e.getSource()==b[i]||e.getSource()==bpoint){
s=s+e.getActionCommand();
text1.setText(s);
break;
}
}if(e.getSource()==badd){
x=Double.parseDouble(s);
flag=1;
text1.setText("");
s="";
}
if(e.getSource()==bsbb){
x=Double.parseDouble(s);
flag=2;
text1.setText("");
s="";
}
if(e.getSource()==bmult){
x=Double.parseDouble(s);
flag=3;
text1.setText("");
s="";
}
if(e.getSource()==bdiv){
x=Double.parseDouble(s);
flag=4;
text1.setText("");
s="";
} if(e.getSource()==bclear){
text1.setText("");
s="";
flag=0;
}if(e.getSource()==beq){
switch(flag){
case 1:
{
x=Double.parseDouble(s)+x;
String s=String.valueOf(x);
text1.setText(s);break;
} case 2:
{
x=x-Double.parseDouble(s);
String s=String.valueOf(x);
text1.setText(s);break;
}
case 3:
{
x=Double.parseDouble(s)*x;
String s=String.valueOf(x);
text1.setText(s);break;
}
case 4:
{
if(Double.parseDouble(s)==0){text1.setText("除数不能为0!");break;}
x=x/Double.parseDouble(s);
String s=String.valueOf(x);
text1.setText(s);break;
}
}
}
}
}
解决方案 »
- 求大神帮忙!这个程序数组为什么会溢出?
- 在线求助:键盘事件如何返回功能键F2的值(字符串,数值都可以)
- Java中的代码块种类
- String s = new String("xyz");创建了几个String Object?
- 晕,J2RE不能安装!!!
- 求助!!org.w3c.dom.Document 对象,怎么控制其Encoding ??急!
- Thinking in java2 里的一个包的问题。
- JBuilder7安装
- 求教JDBC连接SQL2000
- BufferedReader使用readLine()方法返回一个奇葩的null值,麻烦指教
- CallableStatement如何获取SQL2000中存储过程的返回列表
- 下个月就要开始学习JAVA了!
在命令行中用appletviewer运行;或者编写一个html文件,然后把编译后的字节码文件嵌入进去运行
如下:
<applet code=jsq width=100 height=100>
</applet>Thanks
Hima
该怎么样才可以把它改为application呢?
最后将html和class文件放在一个目录,然后直接运行html文件就可以了
<html>
<head>
<title>WelcomeApplet</title>
</head>
<body>
<hr/>
<applet code="appletname" width="400" height="200">
<p
</applet>
</body>
</html>