当前位置: 技术问答>java相关
奇怪的事,有兴趣的朋友请进来看看
来源: 互联网 发布时间:2015-01-18
本文导语: import java.applet.Applet; import java.awt.*; import java.net.URL; public class PaintBanner extends Applet { Image testImage; public void init() { testImage = getImage("http://www.magnastar.com/banner.gif"); } public void paint(Graphics g) { g.drawImage(te...
import java.applet.Applet;
import java.awt.*;
import java.net.URL;
public class PaintBanner extends Applet {
Image testImage;
public void init() {
testImage = getImage("http://www.magnastar.com/banner.gif");
}
public void paint(Graphics g) {
g.drawImage(testImage, 0, 0, this);
}
}
上面这段程序以编译就说不能解析符号:方法getImage(java.lang.string),到底getImage和url应该如何用?上面程序是从编程详解上抄下来的
import java.awt.*;
import java.net.URL;
public class PaintBanner extends Applet {
Image testImage;
public void init() {
testImage = getImage("http://www.magnastar.com/banner.gif");
}
public void paint(Graphics g) {
g.drawImage(testImage, 0, 0, this);
}
}
上面这段程序以编译就说不能解析符号:方法getImage(java.lang.string),到底getImage和url应该如何用?上面程序是从编程详解上抄下来的
|
把banner.gif和applet放在同一个目录下,然后用
testImage =getImage(getCodeBase(),"banner.gif");
testImage =getImage(getCodeBase(),"banner.gif");
|
加入:import java.lang.*;
|
而且,Load一个image的语句是:
image = Toolkit.getDefaultToolkit().getImage("http://www.magnastar.com/banner.gif");
image = Toolkit.getDefaultToolkit().getImage("http://www.magnastar.com/banner.gif");
|
一点都不奇怪
编译通过
什么编程详解?好象很破!!
import java.applet.Applet;
import java.awt.*;
import java.net.*;
public class PaintBanner extends Applet
{
Image testImage;
URL u ;
public void init()
{
try
{
u = new URL("/banner.gif");
testImage = getImage(u);
}
catch(MalformedURLException mf)
{
}
}
public void paint(Graphics g)
{
g.drawImage(testImage, 0, 0, this);
}
}
编译通过
什么编程详解?好象很破!!
import java.applet.Applet;
import java.awt.*;
import java.net.*;
public class PaintBanner extends Applet
{
Image testImage;
URL u ;
public void init()
{
try
{
u = new URL("/banner.gif");
testImage = getImage(u);
}
catch(MalformedURLException mf)
{
}
}
public void paint(Graphics g)
{
g.drawImage(testImage, 0, 0, this);
}
}