A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© rxtm 中级黑马   /  2015-7-23 12:23  /  352 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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();
}
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马