java初学。加载图片

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

上一篇:C++模拟实现JDK中的ArrayList和LinkedList


下一篇:C++工具系列博文合集