Hey again, I've got another question for y'all. When drawing images, etc. to a GUI, does it matter where your draw method is? Or do you have to do something a little different depending on where it is?
Here's basically what I have:
code:
public class Manager extends Core
{
public static void main(String[] args)
{
//initialize full screen GUI
init(); //in Core
scn = this.getScreenManager(); //from Core
//show splash screen
new Splash(2000).show(); //displays for 2 seconds
//show login menu
Login login = new Login();
login.setScreen(scn);
login.show();
}
}
code:
public class Login extends Menu
{
public Login()
{
super();
}
public void show()
{
//create sprites
//add sprites to an ArrayList (in DrawStuff)
display();
}
public void display()
{
Graphics2D g = getScreen().getGraphics();
draw(g);
g.dispose();
getScreen().update();
}
public void draw(Graphics2D g2d)
{
for(int i=0;i<getInUse().size();i++)
{
Sprite pfft = (Sprite)getInUse().get(i);
AffineTransform trans = g2d.getTransform();
trans.scale(getScale(), getScale());
trans.translate(Math.round(pfft.getX()), Math.round(pfft.getY()));
g2d.drawImage(pfft.getAnimation().getImage(), trans, null);
}
}
}
code:
public class Menu extends DrawStuff
{
//stuff for menus here
public Menu()
{
super();
}
}
code:
public class DrawStuff
{
private ScreenManager screen;
private ArrayList inUse;
private double scale;
public DrawStuff()
{
inUse = new ArrayList(10);
}
public void setScreen(ScreenManager screen)
{
this.screen = screen;
}
public ScreenManager getScreen()
{
return screen;
}
public ArrayList getInUse()
{
return inUse;
}
public void draw(Graphics2D g2d)
{
for(int i=0;i<this.inUse.size();i++)
{
Sprite pfft = (Sprite)this.inUse.get(i);
AffineTransform trans = g2d.getTransform();
trans.scale(this.scale, this.scale);
trans.translate(Math.round(pfft.getX()), Math.round(pfft.getY()));
g2d.drawImage(pfft.getAnimation().getImage(), trans, null);
}
}
}
If I run that the way it is, it works fine and draws the sprites correctly (using the draw method in Login). However, if I comment out that draw method so it uses the one in DrawStuff, all I get is a black screen. The sprites are still there (enough so that I can click on them), but you just can't see them. I've put various printlns in throughout both draw methods, and everything seems to be right (my ArrayList is the right size and contains the right objects, etc).
It seems like it's drawing everything, but then it's drawing the black screen over it all. Any ideas? I've been staring at this for 5-6 hours now and it's turning into one big blur...
Any thoughts are appreciated,
LF
(Edited by Lord_Fukutoku on 11-03-2004 23:44)