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

您没有登录

» 中国Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 向大侠们请教一个菜鸟问题
午夜蓝调





发贴: 6
积分: 0
于 2008-10-11 01:22 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,做了个装载和显示本地图片的小程序,改了很多地方,最后没有办法按照书上例子原样写出来,还是报错,依然不能正常显示图片,能请教各位大侠问题出在哪里吗?(我用的eclipse,图片就在workspace下的ImageLoad类文件夹下)源程序如下:
import java.awt.*;
import java.applet.Applet;
/*
* <applet code="ImageLoad" width=300 height=200>
* <param name="image" value="1.jpg">
* </applet>
* */

public class ImageLoad extends Applet {
Image image;

public void init(){
  setBackground(Color.blue);
  image=getImage(getDocumentBase(),getParameter("image"));
  
}
public void paint(Graphics g){
  g.drawImage(image,0,0,this);
}
下面是编译后报的错误:at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
  at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
  at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
  at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
  at ImageLoad.paint(ImageLoad.java:18)
  at sun.awt.RepaintArea.paint(Unknown Source)
  at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
  at java.awt.Component.dispatchEventImpl(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)




Migrating from Java Applets to plugin-free Java technologies
作者 Re:向大侠们请教一个菜鸟问题 [Re:午夜蓝调]
liuzhenke15





发贴: 45
积分: 0
于 2008-12-21 18: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
你尝试一下直接用以下命令编译
javac ImageLoad.java
生成ImageLoad.class后在建立一个html文件(看附件),然后通过
appletviewer test.html
执行即可

个人建议,加入你是初学者,建议用普通的编辑器来编成,用java命令行编译,这样可以清楚java各工具的一些基础,然后再用工具 Smile

test.html (0.25k)




Migrating from Java Applets to plugin-free Java technologies
作者 Re:向大侠们请教一个菜鸟问题 [Re:午夜蓝调]
liuzhenke15





发贴: 45
积分: 0
于 2008-12-21 18: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
在你的例子中,记住把以下文件放在同一个目录
1.jpg
test.html
ImageLoad.class

我已经直接用你的代码编译.class文件成功,看附件

当然,在真正的应用部署中会复杂一些

ImageLoad.class (0.78k)




Migrating from Java Applets to plugin-free Java technologies

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-2016 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923