Active Menu Backrounds

Hello
I am a noob programmer and I was wondering if any one knows how to code a backround to a menu (for a game) so it keeps changing pictures every few second and/or it shows different video clips. For example anyone who has played Rise of Nations or Rome: Total War, the menu is overlayed on a backround of moving art. If it is to complicated to overlay the two would anyone know how to make them into windows? a.k.a. Have a fullscreen game window with the pictures or video clips in an inside window and the menu as a seperate window next to it.

Thanks

The most simple way is to put an animated gif image onto a JButton with ‘new JButton(new ImageIcon(“myanimated.gif”))’

If your game ist runnig in an active rendering loop (as it is supposed to be) you can just make a custom paint()-method for your menu-item which draws an image over it every time the whole frame gets an repaint(). The menu-item can be every kind of AWT or Swing component (Label, Frame, Button, MenuItem, etc.)

pseudocode:



// create the item with a custom paint()-method
JButton menu_item = new JButton() {
  paint(Grahpics g) {
  g.drawImageI(...);  // drawing the bg-image
  g.drawString(...);  // drawing the text over the bg-image
}
}

//add the item to the Frame
Frame.add(menu_item);

while(true) {  //rendering-loop
  menu_item.repaint();
}

Override a JPanel and use it as your ContentPane… in the paintComponent() method, first paint the image and then paint the children…

public void paint(Graphics g)
{
g.drawImage(currentImage);
paintChildren(g);
paintBorder(g);
}

each time you change the ‘currentImage’, call repaint(); and it’ll update.

Thanks i’ll try that :slight_smile: