import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.swing.JFrame;
public class PhotoTest extends JFrame{
Image img;
double x,y;
public void LaunchFrame(){
new PaintThread().start();
setSize(700,700);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public PhotoTest(double x,double y,String path){
this.x=x;
this.y=y;
img=Util.getImage(path);
}
public void paint(Graphics g){
g.drawImage(img, (int)x,(int)y,null);
}
static class Util{
public static Image getImage(String path){
BufferedImage img=null;
URL u=PhotoTest.class.getClassLoader().getResource(path);
try {
img=javax.imageio.ImageIO.read(u);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return img;
}
}
class PaintThread extends Thread{
public void run(){
while(true){
repaint();
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
new PhotoTest(0,0,"PhotoTest/xingkong.png").LaunchFrame();
}
}
http://www.cnblogs.com/stansonwilliam/archive/2012/10/26/2740471.html