转贴import java.awt.*;
import java.applet.*;public class Test extends Applet {
ImageCanvas ip; public void init() {
Image i = getImage(getDocumentBase(), "on.gif");
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(i, 0);
try { tracker.waitForAll(); } catch (InterruptedException e) { ; }
ip = new ImageCanvas(i);
setLayout(new BorderLayout(10,10));
add("Center", ip);
}
}class ImageCanvas extends Canvas {
Image image; public ImageCanvas(Image i) {
super();
image = i;
} public void paint(Graphics g) {
g.drawImage(image, image.getWidth(this) >> 1,
image.getHeight(this) >> 1, this);
}
}
// ImageObserver exampleimport java.awt.*;
import java.awt.image.*;
import java.applet.Applet;public class Test extends Applet implements ImageObserver {
Image img;
int width, height;
boolean image_ready = false; public void init() {
image_ready = false;
img = getImage(getDocumentBase(),"on.gif");
img.getWidth(this);
img.getHeight(this);
prepareImage(img, this);
} public boolean imageUpdate(Image img,int status, int x,
int y, int width, int height){
if ((status & HEIGHT) != 1) {
this.height = height;
}
if ((status & WIDTH) != 1) {
this.width = width;
}
if ((status & ALLBITS) != 1) {
image_ready = true;
repaint();
return true;
}
return false;
} public void paint(Graphics g) {
if (image_ready)
g.drawImage(img, width >> 1, height >> 1,this);
}
}
import java.applet.*;public class Test extends Applet {
ImageCanvas ip; public void init() {
Image i = getImage(getDocumentBase(), "on.gif");
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(i, 0);
try { tracker.waitForAll(); } catch (InterruptedException e) { ; }
ip = new ImageCanvas(i);
setLayout(new BorderLayout(10,10));
add("Center", ip);
}
}class ImageCanvas extends Canvas {
Image image; public ImageCanvas(Image i) {
super();
image = i;
} public void paint(Graphics g) {
g.drawImage(image, image.getWidth(this) >> 1,
image.getHeight(this) >> 1, this);
}
}
// ImageObserver exampleimport java.awt.*;
import java.awt.image.*;
import java.applet.Applet;public class Test extends Applet implements ImageObserver {
Image img;
int width, height;
boolean image_ready = false; public void init() {
image_ready = false;
img = getImage(getDocumentBase(),"on.gif");
img.getWidth(this);
img.getHeight(this);
prepareImage(img, this);
} public boolean imageUpdate(Image img,int status, int x,
int y, int width, int height){
if ((status & HEIGHT) != 1) {
this.height = height;
}
if ((status & WIDTH) != 1) {
this.width = width;
}
if ((status & ALLBITS) != 1) {
image_ready = true;
repaint();
return true;
}
return false;
} public void paint(Graphics g) {
if (image_ready)
g.drawImage(img, width >> 1, height >> 1,this);
}
}
解决方案 »
- 一个String问题,想了半天搞不懂
- if、while、for等 有加{}与没{}问题
- escapeHTML
- junit 单体测试的时候,如果要测的方法,如果返回的是String,int什么的,可以直接用assertEquals,如果返回的是一个object,如果测,
- java有没有什么类可以构建HTTP头结构然后发送到目的地?
- Applet打包jar的运行问题
- 基础问题!
- 各位请帮忙,那里可以下载visibroker for java?
- 一个很实际的问题
- 请求帮助--关于配置java服务器的问题
- 请问如何转化字符串"\\FWV\Epson LQ-1600KII"成"\\\\FWV\\Epson LQ-1600KII"?
- 大家说手工编写JAVA应用程序好不好?
怎么就没有用image当变量的方法得到image的长和宽?
ImageIcon image=new ImageIcon("c:\\1.gif");
int h=image.getIconHeight();//得到图片的高
int w=image.getIconWidth();//得到图片的宽