标题:为啥我的Paint方法没有被调用呢?
取消只看楼主
zhao9302
Rank: 1
等 级:新手上路
帖 子:170
专家分:0
注 册:2007-5-10
 问题点数:0 回复次数:1 
为啥我的Paint方法没有被调用呢?
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowEvent;
import java.util.ArrayList;


public class TankClient extends Frame
{
    public static int GameHeight = 600;
    public static int GameWidth = 800;
    
    static TankClient tc = new TankClient();
    
    ArrayList<Tank> tanks = new ArrayList<Tank>();
    ArrayList<Missile> missiles = new ArrayList<Missile>();
    Image offScreenImage = null;
    
    Tank myTank = new Tank(this.tc,400,200,Direction.U);
    
    public static void main(String args[])
    {   
        tc.loginFrame();
    }
    
    private void loginFrame()
    {
        Frame f = new Frame();
        f.setTitle("TankWar");
        f.setLocation(200, 100);
        f.setSize(GameWidth, GameHeight);
        f.setBackground(Color.GREEN);
        f.setResizable(false);
        f.setVisible(true);
        f.addWindowListener(new java.awt.event.WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
        
        new Thread(new PaintThread()).start();
    }
    
    public void paint(Graphics g)
    {
        g.drawString("EnemyTank Count:" + tanks.size(), 10, 70);
        myTank.paint(g);
    }
    
    public void update(Graphics g)
    {
        if(offScreenImage == null)
            offScreenImage = this.createImage(GameWidth,GameHeight);
        Graphics gOffScreen = offScreenImage.getGraphics();
        Color c = g.getColor();
        gOffScreen.setColor(Color.GREEN);
        gOffScreen.fillRect(0, 0, GameWidth,GameHeight);
        gOffScreen.setColor(c);
        paint(gOffScreen);
        g.drawImage(offScreenImage, 0, 0, null);
    }
    
    private class PaintThread implements Runnable
    {

        public void run()
        {
            repaint();
            while(true)
            {
                try
                {
                    repaint();
                    Thread.sleep(30);
                } catch (InterruptedException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            
        }
        
    }

}
搜索更多相关主题的帖子: Paint awt import Tank java 
2008-08-12 00:57
zhao9302
Rank: 1
等 级:新手上路
帖 子:170
专家分:0
注 册:2007-5-10
得分:0 
谢谢啦

我要一步一步往上爬……
2008-08-12 14:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-227781-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.684915 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved