Mag9102
I don't quite follow what you are saying. How can you create an object to do all of the code for the paint()? Do you mean by creating the shapes first? Please clarify what you are trying to say.
Thanks for the advice though
XP... I mean simplify it... or outsource the code to another class... for example...
Ignore the fact that circle(), square(), and line() don't exist... I'm just demonstrating the idea of moving things...
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
/*Draw 4 shapes of different types*/
g2d.circle(x,y,50,50)
g2d.square(x+50,y,50,50)
g2d.line(x,y+50,50,50);
}[code]
provided there's a lot more sections of code... they can be broken down to other functions in a new class...
[code]public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
/*Draw the same shapes*/
object2.drawShapes(g2d,x,y);
}
public class object2 {
public static void drawShapes(g2d,x,y) {
g2d.circle(x,y,50,50)
g2d.square(x+50,y,50,50)
g2d.line(x,y+50,50,50);
}[/code]
it looks useless from the example... but if you have a dozen different actions you can simplify the paint command by createing seperate functions for each group in a static class and calling those from the paint command...
XP... but I still prefer the idea of having a seperate thread draw the image... update that into the saved area... then call repaint() telling paint to output the BufferedImage....
It's much better for games when you have strict framerates seperate from how fast the paint command executes... cause putting frame info inside of a paint command is to unpredictable to be stable... that's why you use steps, sleeps, and threads...