Start New Discussion within our Software Development Community
private void menuButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
   img = new ImageIcon("DeathRun.png");
   Graphics g = startMenu.getGraphics();
   img.paintIcon(null, g, 0, 0);

The code is very simple for this method but here is my problem. I have a menu that I want to display an image behind. When I hit the menu button the menu comes up the image flashes VERY quickly and only part of it flashes, then it goes away.

If I set a button on the menu to run just the last 3 lines of the code above then the image shows up in the background which is what I want. So why can't I click on a button in a different panel, bring up the menu panel and show the image? It just doesn't make sense.

I've done a little testing and I threw startMenu.paintAll(g) behind the code in the button that DOES show the image, and it does the same thing as when I switch panels and try to show the image.

Ok well I fixed it. I got rid of the panels all together and I'm going to just put most of the stuff on the applet itself. I was trying to make the panels opaque but it wasn't working.
So everything is going to be on the applet, and I made my own paint method which is below. I then set my image icon in init(). Then when I wanted to change the background like when I went into the options menu or the how-to menu I would just change the image icon then repaint.

public void paint(Graphics g)
   img.paintIcon(null, g, 0, 0);
This article has been dead for over six months. Start a new discussion instead.