Topic: getImage(new URL)编译不能通过

  Print this page

1.getImage(new URL)编译不能通过 Copy to clipboard
Posted by: 一枝梅
Posted on: 2005-06-02 08:24

import java.applet.*;

import java.net.*;

import java.awt.*;

public class imag extends Applet{

Image image;

public void init() {

String url = “http://www.shu.edu.cn/~xyx/img/shnet.jpg“;

try {

image = getImage(new URL(url));

} catch(Exception e){}

}

public void paint(Graphics g) {

g.drawImage(image, 0, 0,this);

}

}

以上是我在网上摘抄的,怎么编译出错?

2.Re:getImage(new URL)编译不能通过 [Re: 一枝梅] Copy to clipboard
Posted by: why
Posted on: 2005-06-02 10:26

String url = “http://www.shu.edu.cn/~xyx/img/shnet.jpg“;
Dead
String url = "http://www.shu.edu.cn/~xyx/img/shnet.jpg";
Did you ever read the error messages?

3.Re:getImage(new URL)编译不能通过 [Re: 一枝梅] Copy to clipboard
Posted by: wind520sand
Posted on: 2005-06-02 11:51

我查了在JDK1.5的API文档,在Image 没有找到有getImage();方法啊。
到是有个getGraphics();的方法啊
还有上边的类名 imag 应该大写第一个字母啊 Imag
还有就是在String url = "http://www.shu.edu.cn/~xyx/img/shnet.jpg"的引号应该是英文状态下的。而不是中文状态下的啊!
我该了上边的两个错误后,可以运行了。但是什么东西也没有啊!
我不知道这个到底在作什么的?
可以说一下吗?

4.Re:getImage(new URL)编译不能通过 [Re: wind520sand] Copy to clipboard
Posted by: why
Posted on: 2005-06-02 12:10

wind520sand wrote:
我查了在JDK1.5的API文档,在Image 没有找到有getImage();方法啊。

in java.applet.Applet, otherwise it would be image.getImage(...), which doesn't exist
http://java.sun.com/j2se/1.5.0/docs/api/java/applet/Applet.html#getImage(java.net.URL)

5.Re:getImage(new URL)编译不能通过 [Re: 一枝梅] Copy to clipboard
Posted by: wind520sand
Posted on: 2005-06-02 13:00

我知道了。开始我是查java.awt.image
后来我觉得是不是applet的。我又查了一次找到了!·不过刚才去吃饭了。所以就没及时更新了!呵呵
那么请问。这个是不是显示一图片在APPLET中啊。可是什么都没有啊

6.Re:getImage(new URL)编译不能通过 [Re: 一枝梅] Copy to clipboard
Posted by: yinpeng263
Posted on: 2005-06-08 03:54

For image

http://www.java2s.com/ExampleCode/2D-Graphics-GUI/Image.htm

For applet\

http://www.java2s.com/ExampleCode/Swing-JFC/Applet.htm


   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