为啥我的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();
}
}
}
}
}