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
-
Getting frustrated need help please
I just got an iPod touch for Christmas. Used it on my home computer works great no issues, attempted to use it on my home office computer and I get a message saying that I need the newest version of itunes and Apple Mobile Device Support. I have the current version installed but just to be sure I went to the website and downloaded and installed the version shown. During installation it hit a certain point and began "rolling back" everything. I received an error message saying that itunes could not be installed.
At this point I decided to attempt to uninstall itunes and try a clean install. I uninstalled itunes through "Add/Remove Programs" as well as quick time, bonjour and apple software update. However I cannot uninstall Apple Mobile Device Support, just like the itunes install it reaches just to the end and then rolls back everything.
I have searched the discussion boards and the Apple web site and followed all of the advice to no avail. I have tried using the "change" and "remove" buttons in "Add/Remove Programs", no luck. I have opened MSConfig and stopped all non vital programs from running upon startup, no luck. I have attempted to manually delete the files, all but one will delete, that file is "Locked or in use by another program". I tried changing the file name, no luck. I tried deleting the files from C:\ prompt, no luck.
Ready to throw the computer out the window any help or suggestions would be appreciated. ThanksNo thoughts?
-
How can I add a new Template to My Templates in Pages? I've read most of the discussions on the subject but it doesn't work for me. By the time I reach the Templates folder, I only see templates for Numbers and not for Pages. Need help, please. Thanks
Si vous avez utilisé la commande Save As Template depuis Pages, il y a forcément un dossier
iWork > Pages
contenant Templates > My Templates
comme il y a un dossier
iWork > Numbers
contenant Templates > My Templates
Depuis le Finder, tapez cmd + f
puis configurez la recherche comme sur cette recopie d'écran.
puis lancez la recherche.
Ainsi, vous allez trouver vos modèles personnalisés dans leur dossier.
Chez moi, il y en a une kyrielle en dehors des dossiers standards parce que je renomme wxcvb.template quasiment tous mes documents Pages et wxcvb.nmbtemplate à peu près tous mes documents Numbers.
Ainsi, quand je travaille sur un document, je ne suis pas ralenti par Autosave.
Désolé mais je ne répondrai plus avant demain.
Pour moi il est temps de dormir.
Yvan KOENIG (VALLAURIS, France) mercredi 23 janvier 2011 22:39:28
iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
My iDisk is : <http://public.me.com/koenigyvan>
Please : Search for questions similar to your own before submitting them to the community -
I am trying like **** to download itunes 10.6.3 (64 bit - Windows 7) and I keep getting "the installer was interrupted before the requested operations for iTunes could be completed. Your systems has not been modified." I NEED HELP, PLEASE!
I got it figured out myself... yaaaaay for me!
-
After my iphone4S update to 7.0.6, it have a problem that keep searching network then no service show on display. Can't call. I have try check sim card, reset network settings, and restore my iphone. Still not working at all. Need help please.Urgent.TQ
Izit software or hardware? Confuse:(
Only can use wifi now.
Any way thanks guys for ur suggestion:) amishcake and simes -
Bought a new macbook and want to manually manage music onto my iphone 4s (as it is already full of music from old windows laptop) but when i click 'manually manage' and then 'apply' i get the message saying it will erase everything already on there. Need help please!
Before you sync your iPhone make sure that all the music that was synced to your phonereviously has been copied to your iTunes on the new MacBook Pro. Then when you connect your phone you will be able to either sync all music or select only those playlists that you want on the phone.
-
Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. Then I playing game I can see what someone else trying connecting to my game And I don't know what to do.So if you can help me please? I don't wanna lose my game.
Contact iTunes
Contact iTunes -
Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. When I playing game I can see what someone else trying connecting to my game And I don't know what to do.So if you can help me please? I don't wanna lose my game.
Hello Vaidas Vaidas,
It sounds like you are noticing someone else is accessing your Clash of Clans data by playing the game and you have tried to reset your Apple ID password. If you are following the steps outlined in this article:
Apple ID: Changing your password
http://support.apple.com/kb/ht5624
What is preventing you from changing your password? Any error messages or prompts?
Thank you for using Apple Support Communities.
All the best,
Sterling -
i dont know how i got my photos to my ipod touch from my pc and now i wanna delete them but couldn't. so need help. please let me know.
To turn off auto sync - launch iTunes and go to Edit>Preferences>Devices - check the box at the bottom that says - Prevent iPod, iPhones and iPads from syncing automatically. Click OK and then quit iTunes.
Connect your iDevice to your PC.
Launch iTunes,
Click on the device name on the left side of the iTunes Window.
Click on the Photos Tab in the iTunes window on the right.
Untick all of the photos or albums that you want to remove.
Click on Apply in the lower right corner of iTunes
If you untick or uncheck the Sync Photos heading and then click Apply it will remove all of the photos from the device when it syncs. In this screenshot - I have only certain albums and events selected to sync. -
My iPhone 6 can't find my macbook pro on the airdrop list, although everything is in place, bluetooth, wi fi gets, need help please ?
Dear Niel, thank you but my mac is (MacBook Pro (Retina, 15-inch, Early 2013).
and i can send from it to my iPhone , but not vice versa -
After many months of non-use, when I tried to open Photoshop CS4 Extended, I got an error message 148.3. "Licensing for this product has stopped working." I need help, please.
Error "Licensing has stopped working" | Windows
Error "Licensing has stopped working" | Mac OS
Mylenium -
I need help please I keep getting error messega 21 when i try uploading my iPhone 4 s!!!!!!!!! omg some one please tell me if and how to fix this please. thank you!!!
Hopefully this link will help you: http://support.apple.com/kb/HT2109
-
Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.
Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.
-
After updating my Iphone 5 my lock button isnt working well .... Need help please ..
First, read here:
https://ssl.apple.com/support/iphone5-sleepwakebutton/
See if your phone is affected. -
hi
i need help please . when i want to buy app from store ask me the security question
but i forgot the answer
so i need to the link to rest answer of security questionThe Best Alternatives for Security Questions and Rescue Mail
a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
b. Call Apple Support in your country: Customer Service: Contact Apple support.
c. Rescue email address and how to reset Apple ID security questions. -
Hi I need help please .... I have my credit card information in my account ... But I wanted to delete & I like too add a App Store card
Hi, Ajchenicholas.
Credit cards attached to an Apple ID can be removed and payment method changed to none as long as there is not an outstanding balance. The article below will walk you through this process.
iTunes Store: Changing account information
http://support.apple.com/kb/ht1918
You can always add an iTunes Gift Card to your account at any time. Here are the steps that will walk you through adding an iTunes Gift Card.
iTunes Store: How to redeem a code
http://support.apple.com/kb/ht1574
Cheers,
Jason H.
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
-
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