class pc {static double ad=8; } <-- ??? public class C4 extends Applet { public void main(Graphics g) {pc m=new pc(); pc m1=new pc(); m.ad=0.1; g.drawString("m1="+m1.ad,20,50); g.drawString("m="+m.ad,20,90); } }
看错了 是这里: public void main(Graphics g) --> public static void main(String args[])
把C4.java改成下面那样:import java.awt.*; import java.applet.*;class pc { static double ad = 8; }public class C4 extends Applet { public void paint(Graphics g) { pc m = new pc(); pc m1 = new pc(); m.ad = 0.1; g.drawString("m1=" + m1.ad, 20, 50); g.drawString("m=" + m.ad, 20, 90); } }然后再按ludf(lu)的方法写个html运行
类名要和文件名一致,要extends Applet就要paint()不然就要有main()
To kfigri(缺氧的生鱼片)//各位帮帮忙啊...帮忙找找错误...我把class堪入到html文件中还是不啊...提示载入applet小应用程序失败...........问题可能跟你的JRE配置有关。如果你是先安装JDK,然后又安装了JBuilder8以上版本的话,JRE会被改成JBuilder自带的JDK。你可以在命令行用java -version看看。建议删除原来的JDK,然后重新安装JDK。我发现applet在MyIE里也不能装载。
{static double ad=8;
} <-- ???
public class C4 extends Applet {
public void main(Graphics g)
{pc m=new pc();
pc m1=new pc();
m.ad=0.1;
g.drawString("m1="+m1.ad,20,50);
g.drawString("m="+m.ad,20,90);
}
}
是这里:
public void main(Graphics g)
-->
public static void main(String args[])
paint()
里面再用 Graphics g
呵呵
to:telenths(_非法操作_)
呵呵,你错了
他继承的是Applet
你加一个
public static void main(String args[]){
AppletClass AC = new AppletClass();
AC.init();
AC.start();
}
看有用没?
不行耶,,用了后错误更多...另外..class需要和html文件在一个文件夹吗?
<HTML>
<HEAD>
<TITLE> C4 Example </TITLE>
</HEAD>
<BODY>
<APPLET CODE="C4 .class" WIDTH=500 HEIGHT=300>
</APPLET>
</BODY>
</HTML>然后用appletviewer运行浏览.
import java.applet.*;class pc {
static double ad = 8;
}public class C4 extends Applet {
public void paint(Graphics g) {
pc m = new pc();
pc m1 = new pc();
m.ad = 0.1;
g.drawString("m1=" + m1.ad, 20, 50);
g.drawString("m=" + m.ad, 20, 90);
}
}然后再按ludf(lu)的方法写个html运行
但是弹出来的applet上面什么也没有,,咱没有什么m1=
m2=.的东东哦,
但是弹出来的applet上面什么也没有,,咱没有什么m1=
m2=.的东东哦,
g.drawString("m1=" + m1.ad, 20, 50);
g.drawString("m=" + m.ad, 20, 90);弹出来的applet上自然也就什么都没有了