Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to add Image Icons to a Gui one at a time but they all add together

 
Mark McG
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

I have the following code.

Basically what I am trying to do is add each of the 4 labels (Which contain an image icon of a flag) to a GUI.

I want one flag added, a break for a couple of seconds, then a second one added and so on.

At the moment, nothing is happening for about 30 seconds and then they all appear on the GUI at once. When I change the code to add buttons as oppose to labels with image icons, they are added one at a time the way I want it to be. Therefore I know the code does work, but dosnt seem to work for labels/labels with image icons.

Can someone advise as to where they think I could be going wrong?

Thanks,
Mark






ImageIcon FranceFlagIcon = new ImageIcon("FranceFlagPic.jpg");
Image FranceFlagImage = FranceFlagIcon.getImage().getScaledInstance(80, 100, Image.SCALE_SMOOTH);
FranceFlagIcon.setImage(FranceFlagImage);

ImageIcon IrelandFlagIcon = new ImageIcon("IrelandFlagPic.jpg");
Image IrelandFlagImage = IrelandFlagIcon.getImage().getScaledInstance(80, 100, Image.SCALE_SMOOTH);
IrelandFlagIcon.setImage(IrelandFlagImage);

ImageIcon EnglandFlagIcon = new ImageIcon("EnglandFlagPic.jpg");
Image EnglandFlagImage = EnglandFlagIcon.getImage().getScaledInstance(80, 100, Image.SCALE_SMOOTH);
EnglandFlagIcon.setImage(EnglandFlagImage);

ImageIcon SpainFlagIcon = new ImageIcon("SpainFlagPic.jpg");
Image SpainFlagImage = SpainFlagIcon.getImage().getScaledInstance(80, 100, Image.SCALE_SMOOTH);
SpainFlagIcon.setImage(SpainFlagImage);


JLabel EnglandFlagLabel = new JLabel(EnglandFlagIcon, JLabel.LEFT);
JLabel IrelandFlagLabel = new JLabel(IrelandFlagIcon, JLabel.LEFT);
JLabel FranceFlagLabel = new JLabel(FranceFlagIcon, JLabel.LEFT);
JLabel SpainFlagLabel = new JLabel(SpainFlagIcon, JLabel.LEFT);


try
{


add(SpainFlagLabel);
SpainFlagLabel.setBounds(10,50,100,100);

Thread.sleep(1500);

add(SpainFlagLabel);
SpainFlagLabel.setBounds(10,50,100,100);

Thread.sleep(1500);

add(SpainFlagLabel);
SpainFlagLabel.setBounds(10,50,100,100);

Thread.sleep(1500);

add(SpainFlagLabel);
SpainFlagLabel.setBounds(10,50,100,100);

Thread.sleep(1500);

}
catch(InterruptedException e)
{
}
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read Concurrency in Swing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic