开发者

Simple Java Graphics

I need to create some simple graphics using java. Basically what I need to do is draw a car using the Graphics class and make it move across a frame.开发者_JS百科 I think that the way I should do this is:

Paint the graphics on a JPanel

Put the jpanel on the jframe

Then move the jpanel across the jframe

To give this illusion of movement I'm thinking that I should dynamically change the layoutmanager. Does this seem like a good or bad design?


When overriding paintComponent(Graphics), it is often best done in a JComponent rather than a JPanel.

As for moving the car, I would tend to draw it to a BufferedImage then draw the BufferedImage at different positions to simulate movement. The repaints can be controlled by a javax.swing.Timer.


I think it would be a much better idea to make an object with a paint method that is a car. Then you can move this car around the jFrame and just call paint on it :D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜