
java 小程序查看器 启动:未初始化小程序 请教高手啊。我是新学JAVA
//calculation.java
import java.awt.*;
import java.applet.Applet;
public class calculation extends Applet
{
public void init()
{
setLayout(new BorderLayout());
add("west",new Button("/"));
add("west",new Button("*"));
add("west",new Button("-"));
add("west",new Button("+"));
Panel p= new Panel();
p.setLayout(new GridLayout(3,3));
for(int i=9;i>0;i--)
{
String lbl=(new Integer(i)).toString();
p.add(new Button(lbl));
}
add ("center",p);
}
}
编译是可以成功的。但是就是查看不了。要怎么解决呢?我写的html文件:<html>
<body>
<applet code="calculation.class"width=200 height=200>
</applet>
</body>
</html> 展开
你程序写错了,应该是这样的:
注意是:add(new Button("/"),BorderLayout.WEST);
add (p,BorderLayout.CENTER);
import java.awt.*;
import java.applet.Applet;
public class calculation extends Applet
{
public void init()
{
setLayout(new BorderLayout());
add(new Button("/"),BorderLayout.WEST);
add(new Button("*"),BorderLayout.WEST);
add(new Button("-"),BorderLayout.WEST);
add(new Button("+"),BorderLayout.WEST);
//add("west",new Button("*"));
//add("west",new Button("-"));
//add("west",new Button("+"));
Panel p= new Panel();
p.setLayout(new GridLayout(3,3));
for(int i=9;i>0;i--)
{
String lbl=(new Integer(i)).toString();
p.add(new Button(lbl));
}
add (p,BorderLayout.CENTER);
}
}
import java.awt.*;
import java.applet.*;
public class calculation extends Applet
{
public void init()
{
setLayout(new BorderLayout());
add(new Button("/"),BorderLayout.WEST);
add(new Button("*"),BorderLayout.EAST);
add(new Button("-"),BorderLayout.SOUTH);
add(new Button("+"),BorderLayout.NORTH);
Panel p= new Panel();
p.setLayout(new GridLayout(3,3));
for(int i=9;i>0;i--)
{
String lbl=(new Integer(i)).toString();
p.add(new Button(lbl));
}
add (p,BorderLayout.CENTER);
}
}
这里 width 前面要空格 你这里没有。。。。
然后要保证你这个html文件和calculation.class文件在同一个目录下
你再用浏览器打开看看