FRUSTRATED! Need help, please!

I have written a program for my Pacman maze (see code below).
The program compiles and displays the maze, but the problem is when I minimize the window and miximize it again, the display disappears or becomes corrupted. I thought I need to use repaint or update. HOWEVER this is where it gets interesting. When I have any kind of loop in my paint() method, for example the nested "for" loop in the code below which paints the maze on the screen based on the "board" array, each time I resize or minimize the window, the display becomes corrupted. BUT, if I take the loops out and just use any draw statement to paint something on the screen, I dont have the same problem. And the program repaints the screen perfectly when the window is resized or minimized.
Please help me, I have already spent a long time on this problem.
THanks in advance.
here is the code.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Maze extends JFrame
     static int board[][] = { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                                   {1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
                                   {1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1},
                                   {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                                   {1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1},
                                   {1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1},
                                   {1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1},
                                   {1,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1},
                                   {1,1,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1},
                                   {0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
                                   {1,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,1},
                                   {1,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1},
                                   {1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1},
                                   {1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1},
                                   {1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1},
                                   {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                                   {1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1},
                                   {1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
                                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} };
     int count1 = 0;
     int count2 = 0;
     int xbound = 25;
     int ybound = 50;
     public Maze()
          super ("PacMan Maze");
          setSize(800,800);
          show();
     public void paint (Graphics g)
          for(count1=0; count1 < 19; count1++)
               for(count2=0; count2 < 19; count2++)
                    switch (board[count1][count2])
                         case 0:
                              g.setColor(Color.blue);
                              g.fillRect(xbound,ybound,35,35);
                         break;
                         case 1:
                              g.setColor(Color.white);
                              g.fillRect(xbound,ybound,35,35);
                              g.setColor(Color.blue);
                              g.drawRect(xbound,ybound,35,35);
                         break;
                         xbound = xbound + 35;     
          ybound = ybound + 35;
          xbound = 25;
     public static void main (String args[])
          Maze app = new Maze();
          app.addWindowListener(
               new WindowAdapter() {
                    public void windowClosing( WindowEvent e)
                         System.exit(0);
}

I think you did not reset the xbound/ybound variables after the paint, therefore the numbers keep increasing each time the paint method is called.
Try setting both variables to 0 at the start of the paint method.

Similar Messages

Maybe you are looking for

  • HTTP error:while testing ADF11g app from external wls10.3

    Hi I deployed the ADF 11g App to external wls. when testing from browser i am getting only layouts of my page. i am not getting the table rows in my page. The error in domain log in server i got is: HTTP     Error     BEA-101017     [weblogic.servlet

  • Manually Adding Track Numbers Doesn't Work!

    I would like to make a "custom album" for an artist, a greatest hits designed by me, if you will. The songs are all by a single artist, but come from various sources. Some were purchased from iTunes Music Store, some were imported directly from CDs,

  • CS3/4, JS Amateur question: how remove all empty text frames?

    I'm an amateur, and thought it would be a straightforward matter to write a script that simply deletes all empty text frames in all of a document's stories. Here's my second attempt: var myDocument = app.activeDocument; var myStories = myDocument.sto

  • IDOC control record mapping - Sender Partner number defaulted to log. sys.

    My PI scenario is file to IDOC scenario. I have ticked "apply values from payload" checkbox, so Sender Partner Number is being defaulted to logical system assigned to my business system. Logical system name has to be unique in PI. My understanding is

  • Java 5 threads in linux

    Hi, I am using the following java version in Linux java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode) Threads are created using the source code: pr