Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 为什么这个Applet不能在浏览器显示啊? [精华]
Cascading





发贴: 18
积分: 0
于 2004-10-11 11:57 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这个是 HelloWorldApplet .java


import java.awt.Graphics;

class HelloWorldApplet extends java.applet.Applet {
public void paint(Graphics g) {
g.drawString("Hello world!",5,25);
}
}


下面这个是HelloWorldApplet.htm

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
<applet code="HelloWorldApplet.class" width="200" height="30">
</BODY>
</HTML>


在DOS下用appletviewer命令查看,总是说applet载入失败,怎么回事啊?



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
ditty

负资产小资

CJSDN高级会员


发贴: 1038
积分: 143
于 2004-10-11 11:59 user profilesend a private message to usersend email to dittysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
codebase="."



内忧外患的时代,洗心革面,阿咪豆腐~
作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
Cascading





发贴: 18
积分: 0
于 2004-10-11 12:01 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
哪里错了,能详细解释一下么?
我是照着书打的,不知道错在哪里


在浏览器里运行就是一个灰屏


why edited on 2004-10-11 13:30

作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
cjyzpcl





发贴: 64
积分: 4
于 2004-10-12 14:49 user profilesend a private message to usersend email to cjyzpclsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请问html文件和class文件是放在一个文件夹下面的吗?


作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
掙銭養老婆





发贴: 4
积分: 0
于 2004-10-13 12:44 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的也是呀,哪位大哥教一下


作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
HW升





发贴: 15
积分: 0
于 2004-10-14 21:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1.HelloWorldApplet.htm缺少 </APPLET>
2.将类HelloWorldApplet定义为public访问级别



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
q_yuan





发贴: 174
积分: 3
于 2004-10-15 11:08 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我做的APPLET有时候也是不能显示,但有时候可以.很迷茫!


作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
beckham





发贴: 24
积分: 0
于 2004-10-17 19:34 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.applet.*;
import java.awt.*;
public class Example2 extends Applet
{ public void paint(Graphics g)
{int i,j;
int k=20;
for(j=2;j<=100;j++)
{for(i=2;i<=j/2;i++)
{if(j%i==0)
break;
}
if(i>j/2)
{ k=k+20;
g.drawString("素数是"+j,20,k);
}
}
}
}

<applet code=Example2.class height=1000 width=300>
</applet>

上面这个也是 高手帮看下  谢谢



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:HW升]
beckham





发贴: 24
积分: 0
于 2004-10-17 19:36 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
HW升 wrote:
1.HelloWorldApplet.htm缺少 </APPLET>
2.将类HelloWorldApplet定义为public访问级别

应该是这样的 你的书不大好
高手再看看我的



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:beckham]
HW升





发贴: 15
积分: 0
于 2004-10-18 12:27 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
beckham wrote:
import java.applet.*;
import java.awt.*;
public class Example2 extends Applet
{ public void paint(Graphics g)
{int i,j;
int k=20;
for(j=2;j<=100;j++)
{for(i=2;i<=j/2;i++)
{if(j%i==0)
break;
}
if(i>j/2)
{ k=k+20;
g.drawString("素数是"+j,20,k);
}
}
}
}

<applet code=Example2.class height=1000 width=300>
</applet>

上面这个也是 高手帮看下  谢谢


上面的我调试过了,好象没问题啊!
???



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
beckham





发贴: 24
积分: 0
于 2004-10-18 15:02 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
yun o
我同学也是 我给他调了下也出来了 可在我上面就是一片灰 呵呵 看来不知道什么地方出问题了 只有重装jdk了 呵呵



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:HW升]
小好





发贴: 8
积分: 0
于 2004-10-18 21:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
HW升 wrote:
1.HelloWorldApplet.htm缺少 </APPLET>
2.将类HelloWorldApplet定义为public访问级别


我和楼主也是同样的问题

按照上面的修改后还是一片灰白 请问到底是哪里出问题了呢?

不胜感激



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:小好]
HW升





发贴: 15
积分: 0
于 2004-10-19 11:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
小好 wrote:
我和楼主也是同样的问题

按照上面的修改后还是一片灰白 请问到底是哪里出问题了呢?

不胜感激


用最新的jdk了吗?

实在不行的话把代码贴出来看看先啊!



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
yclc





发贴: 37
积分: 1
于 2004-10-20 11:26 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.awt.*;
import java.applet.Applet;
public class test extends Applet {
public void paint(Graphics g)
  {
g.drawString("Hello world!",5,25);
}
}

上述代码已经调试过了,可以通过。JDK1.4.2
运行方式1:appletviewer test.html(自己先写个HTML先)
运行方式2:自己先写个HTML先,如果直接用CODE不行,就用HTML转换器转一下,JDK自带,注意:要放到WEBSERVER 下看,直接打开HTML会提示APPLET启动失败,以WEB形式打开就OK



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
xuxiang84





发贴: 23
积分: 0
于 2004-10-20 18:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
还要看看环境变量设好没有!!


作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
gj97c125





发贴: 4
积分: 0
于 2004-10-21 19:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的也是啊,在学校机器上能显示,在自己的机器上就不行了

//源程序:bh.java
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;


public class bh extends Applet implements ActionListener{
Label label1=new Label("输入十进制数");TextField field4=new TextField(6);
Label label2=new Label("二进制数为");TextField field1=new TextField(6);
Label label3=new Label("八进制数为");TextField field2=new TextField(6);
Label label4=new Label("十六进制数为");TextField field3=new TextField(6);
Button button1=new Button("变换");


public void init(){ //初始化
setLayout(new GridLayout(5,2));
add(label1);add(field1);
add(label2);add(field2);
add(label3);add(field3);
add(label4);add(field4);
add(button1);
button1.addActionListener(this);
}


public void actionPerformed(ActionEvent e){ //处理按钮事件
int x=Integer.parseInt(field1.getText());
field2.setText(Integer.toBinaryString(x)); // 数值转换为字符窜
field3.setText(Integer.toOctalString(x));
field4.setText(Integer.toHexString(x));
}
}

求高手指点啊


{ Disable Smileys }


why edited on 2004-10-24 18:11

作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
gj97c125





发贴: 4
积分: 0
于 2004-10-21 19:54 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
晕,上面(6)是括号6 (x)是括号x

littledeer1974 edited on 2004-10-31 14:45

作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:HW升]
小好





发贴: 8
积分: 0
于 2004-10-21 22:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
HW升 wrote:
用最新的jdk了吗?

实在不行的话把代码贴出来看看先啊!


import java.awt.Graphics;
import java.applet.*;

public class javaapplet extends Applet{
public void paint(Graphics g){
g.drawString("hello,javaworld!",10,20) ;
}

}


HTML

<HTML>
<BODY>
<TITLE> New Document </TITLE>
<APPLET CODE="javaapplet.class" HEIGHT=200 WIDTH=300>
</APPLET>
</BODY>
</HTML>

错误类型
java.lang.NoSuchMethodError: main
Exception in thread "main"



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
sunzheng





发贴: 5
积分: 0
于 2004-10-24 15:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
I agree the point of "小好".It is right!


作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:小好]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2004-10-24 18:31 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
小好 wrote:
错误类型
java.lang.NoSuchMethodError: main
Exception in thread "main"

我和楼主也是同样的问题
按照上面的修改后还是一片灰白 请问到底是哪里出问题了呢?

到底阁下和楼主是同样的问题(一片灰白)
还是出现java.lang.NoSuchMethodError: main呢?



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
liuyuan310





发贴: 5
积分: 0
于 2004-10-26 11:15 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
步骤:
1:在记事本键入程序javaapplet保存,命名为“javaapplet.java”
2:在记事本写html保存,命名为“javaapplet.html”
3:dos下面 javac javaapplet.java
4:dos下 appletviewer javaapplet.html
本人就是这样通过拉



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
decun





发贴: 35
积分: 0
于 2004-10-26 23:38 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
有一个要 注意的问题就是 如果 .html文件和.class文件不在一个目录下面。
那么要在<applet 最后加上codeBase=路径></applet>
另外就是 如果浏览器不能正常显示
那可以cmd窗口中 用 appletviewer HelloWorld.html 来运行 当然要 .html文件和.class在同一个目录下面吧



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
maoone2003





发贴: 11
积分: 0
于 2004-10-30 15:24 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我也有同样的问题,不过我的applet用appletviewer可以显示,但就是直接打开网页的时候只显示一个灰框,里面什么都没有,不知道为什么


作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
aiff





发贴: 85
积分: 10
于 2004-10-31 14:15 user profilesend a private message to usersend email to aiffsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
朋友们拜托了!!! 关于这个问题在这论坛上问过很多次了~~请你们提问前搜索1下以前提到过的东西 我随便找1个就发现了这个

http://www.cjsdn.net/post/view?bid=1&id=109992&sty=1&tpg=7&age=0

(同情我们斑竹的辛勤劳动....................)



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
装进了魔瓶





发贴: 3
积分: 0
于 2005-01-21 01:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我也是这个问题
我用JBuilder写了个简单的Applet,在Dos下用appletviewer运行正常,直接用IE打开文件的方式也正常。但发布到本地WEB服务器上,用IE调用就是灰框,JAVA控制台报“没有找到类”。
环境变量我都检查了很多遍。
请过来人指点,不胜感激



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
lfxlixiang





发贴: 8
积分: 0
于 2005-01-21 20:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Cascading
其实你的那个Helloword已经打出来了只是看不到.
因为你设的"helloword"的起始位置不在你为applet开辟的范围内.
把<applet code="HelloWorldApplet.class" width="200" height="30">的"width"和"heigth"设大一点试试看.
加油!



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
lfxlixiang





发贴: 8
积分: 0
于 2005-01-24 17:02 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你的那个“HELLO WORD”已经显示了,不过它的起始位置不在你为applite开辟的那个空间的范围内。
你把“g.drawString("Hello world!",5,25);”中的起始位置改大一点试试看。



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
lfxlixiang





发贴: 8
积分: 0
于 2005-01-24 17:03 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你的那个“HELLO WORD”已经显示了,不过它的起始位置不在你为applite开辟的那个空间的范围内。
你把“g.drawString("Hello world!",5,25);”中的起始位置改大一点试试看。



作者 Re:为什么这个Applet不能在浏览器显示啊? [Re:Cascading]
BarryWhite





发贴: 14
积分: 0
于 2005-01-26 17:54 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
先把你的source code 用javac.exe运行一下,使它产生字节码(*.class 文件),然后再浏览器中看



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923