当前位置: 技术问答>java相关
如何显示图象??为什么总是出错?
来源: 互联网 发布时间:2017-04-20
本文导语: 这是我的代码: import java.awt.*; import java.applet.Applet; public class Class1 extends Applet { Image myImage; public void init() { URL url1; url1=new URL("c_/aaa.gif"); myImage=getImage(url1); } public void paint(Graphics g) { g.drawImag...
这是我的代码:
import java.awt.*;
import java.applet.Applet;
public class Class1 extends Applet
{
Image myImage;
public void init()
{
URL url1;
url1=new URL("c_/aaa.gif");
myImage=getImage(url1);
}
public void paint(Graphics g)
{
g.drawImage(myImage,0,0,this);
}
}
提示是:undefined name 'URL’(J0049)
我刚学java不久,请大家帮忙
import java.awt.*;
import java.applet.Applet;
public class Class1 extends Applet
{
Image myImage;
public void init()
{
URL url1;
url1=new URL("c_/aaa.gif");
myImage=getImage(url1);
}
public void paint(Graphics g)
{
g.drawImage(myImage,0,0,this);
}
}
提示是:undefined name 'URL’(J0049)
我刚学java不久,请大家帮忙
|
应该捕获MalformedURLException
try{
url1=new URL("c_/aaa.gif");
myImage=getImage(url1);
}
catch(MalformedURLException e){}
try{
url1=new URL("c_/aaa.gif");
myImage=getImage(url1);
}
catch(MalformedURLException e){}
|
import java.net.*;