sizhiguo
发贴: 5
积分: 0
|
于 2005-11-29 15:51
我的源代码: 你看一下 import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image;
import javax.swing.JLabel;
public class ImageLabel extends JLabel implements Runnable { /** * */ private static final long serialVersionUID = 1L;
public Image images = null;
Thread thread;
public ImageLabel() { thread = new Thread(this); thread.start(); }
public void setImage(Image buf) { this.images = buf;
}
public void paint(Graphics g) { super.paint; Graphics2D g2 = (Graphics2D) g; if (images != null) { g2.drawImage(images, 0, 0, getWidth(), getHeight(), 0, 0, images.getWidth(null), images .getHeight(null), null); } }
public void run() { while (true) { this.repaint(); try { Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } } }
public void update(Graphics g) { paint; } }
只用把这个jlable放到某个位置然后加上 Image image2 = Toolkit.getDefaultToolkit().getImage(f.getAbsolutePath()); picArea.setImage(image2);
|