package myGame;
import java.awt.Image;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.net.URL;
import javax.imageio.ImageIO;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class SmallGame extends JFrame{
Image img=GameUtil.getImage("images/3.jpg");
public void launchFrame(){
setSize(1900,900);
setLocation(100,100);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
new PaintThread().start();
addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e){
System.exit(0);
}
});
}
private double x=200,y=200;
public void paint(Graphics g){
g.drawImage(img,(int)x,(int)y, null);
g.setColor(Color.blue);
g.drawString("活捉一只小胖猪诶",200,200);
x+=3;
y+=3;
}
class PaintThread extends Thread{
public void run(){
while(true){ //重画窗口
repaint();
try {
//repaint();
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args){
SmallGame g=new SmallGame();
g.launchFrame();
}
} |
|