码迷,mamicode.com
首页 > 编程语言 > 详细

java初学。加载图片

时间:2015-05-30 18:10:32      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

public class GameFrame extends Frame{
  private static final int WIDTH=900;
  private static final int HEIGHT=600;
  Man man=new Man();

  public void paint(Graphics g){
    man.draw(g);
  }
  public void loadFrame(){
    this.setSize(WIDTH, HEIGHT);
    this.setLocation(50,50);
    this.setTitle("工作室--洪七公打狗");
    this.setVisible(true);
    new PaintThread().start();
  }
  public static void main(String[] args) {
    new GameFrame().loadFrame();
  }

  class PaintThread extends Thread{
    @Override
    public void run() {
      // TODO Auto-generated method stub
      while(true){
        repaint();
        try {
          Thread.sleep(40);
        } catch (Exception e) {
          // TODO: handle exception

        }
      }
    }
  }
}

 

//Man类

public class Man {

  //加载图片
  private Image img=Toolkit.getDefaultToolkit().getImage("Images/people.jpg");
  public void draw(Graphics g){
    g.drawImage(img, 50, 400, null);
  }
}

java初学。加载图片

标签:

原文地址:http://www.cnblogs.com/wangxiangstudy/p/4540579.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!