我按书上编了一个程序FlowLayout,编译能通过,运行却出一个这样的对话框"我按书上编了一个程序Flowlayout,编译难过,运行就出一个框“ 该系统无法在活动项目中找到一个合适的主方法或htm(l)文件”.程序为
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class FlowLayoutDemo extends Applet implements ItemListener
{
String msg="";
Checkbox Win98,WinNT,Linux,Mac;
public void init()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
Win98=new Checkbox("win98",null,true);
WinNT=new Checkbox("Win NT/2000");
Linux=new Checkbox("Linux/Unix");
Mac=new Checkbox("MacOS");
add(Win98);
add(WinNT);
add(Linux);
add(Mac);
Win98.addItemListener(this);
WinNT.addItemListener(this);
Linux.addItemListener(this);
Mac.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
repaint();
}
public void paint(Graphics g)
{
msg="Current state:";
g.drawString(msg,6,80);
msg="Window 98:"+Win98.getState();
g.drawString(msg,6,100);
msg="Window NT/2000:"+WinNT.getState();
g.drawString(msg,6,120);
msg="Linux/Unix:"+Linux.getState();
g.drawString(msg,6,140);
msg="MacOS:"+Mac.getState();
g.drawString(msg,6,160);
}
}
怎么办啊?急死我了
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class FlowLayoutDemo extends Applet implements ItemListener
{
String msg="";
Checkbox Win98,WinNT,Linux,Mac;
public void init()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
Win98=new Checkbox("win98",null,true);
WinNT=new Checkbox("Win NT/2000");
Linux=new Checkbox("Linux/Unix");
Mac=new Checkbox("MacOS");
add(Win98);
add(WinNT);
add(Linux);
add(Mac);
Win98.addItemListener(this);
WinNT.addItemListener(this);
Linux.addItemListener(this);
Mac.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
repaint();
}
public void paint(Graphics g)
{
msg="Current state:";
g.drawString(msg,6,80);
msg="Window 98:"+Win98.getState();
g.drawString(msg,6,100);
msg="Window NT/2000:"+WinNT.getState();
g.drawString(msg,6,120);
msg="Linux/Unix:"+Linux.getState();
g.drawString(msg,6,140);
msg="MacOS:"+Mac.getState();
g.drawString(msg,6,160);
}
}
怎么办啊?急死我了
写的是Applet,最好嵌入到浏览器中运行,
反正是需要一个HTML文件了
文件的内容就是如下的样子
<applet code="your_class.class">
</applet>然后打开HTML,就可以在浏览器中查看效果了,
或者你也可以用 appletviewer来查看
public class FlowLayoutDemo extends Applet implements ItemListener
add a html file in the same file and add this content in html file
"<applet code="yourclass.class">
</applet>" then save.
compile .java file and run html next.
Method#2. use appletviewer.
add this content in you java file"//<applet code="yourclass.class">
</applet>" attention,it must be comment.
save it and run the command :"appletviewer yourjava.java".
Try these two methods.