Disappearing Window Content - please help?

Hi,
I'm not very familiar with Java at all, but I have to use it for an assignment, part of which involves randomly generating a maze and displaying it on the screen. I use a JFrame object for displaying.
However, sometimes when I run the program, the maze appears for less than a second, then disappears leaving a blank frame. At other times, the frame is completely empty. And sometimes, the maze is displayed the way it should be (this usually happens after a fresh recompiling). My code runs thus:
public class Test
public static void main(String argv[])
JFrame test = new JFrame("nuts");
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setSize(700, 700);
Container content = test.getContentPane();
test.setVisible(true);
// creating maze object called 'maze' here
maze.paint(content.getGraphics());
Here is my paint method:
public void paint (Graphics g) {
int x, y;
for (x = 1; x < 24; ++x)
for (y = 1; y < 39; ++y) {
if ((maze[x][y] & 1) != 0) /* This cell has a top wall */
g.drawLine (x * 10, y * 10, x * 10 + 10, y * 10);
if ((maze[x][y] & 2) != 0) /* This cell has a bottom wall */
g.drawLine (x * 10, y * 10 + 10, x * 10 + 10, y * 10 + 10);
if ((maze[x][y] & 4) != 0) /* This cell has a left wall */
g.drawLine (x * 10, y * 10, x * 10, y * 10 + 10);
if ((maze[x][y] & 8) != 0) /* This cell has a right wall */
g.drawLine (x * 10 + 10, y * 10, x * 10 + 10, y * 10 + 10);
Can anyone please explain to me why my content disappears at times, and is displayed at others? I am in sore need of help, and would be very grateful if someone could give me a hint... If I'm doing something stupid here, my apologies in advance.
Thanks.
MM.

I understand that I didn't set the tags to display my code properly - I'm sorry, I didn't know about it... But I don't quite understand what else I've done wrong. Let me rephrase my question:
I'm trying to print a maze on screen using a JFrame object. Unfortunately, when I run the program (and quit it properly after each time), one of the following happens:
a) The maze is printed correctly.
b) The maze appears for less than a second, then disappears leaving a blank JFrame window.
c) The JFrame window remains blank (which may be the same thing as b, only the maze flashes by too fast for me to notice).
I've gone through a few JFrame tutorials, and I think I've followed the general guidelines. I tried looking for help at other sources - to see if anyone else had trouble with their Jframe content being displayed only sometimes. I even tried setting the Jframe object to always appear on top, but it didn't help. Since I've little experience with coding in Java, I was wondering if someone could please help me by telling me if I'm doing something wrong?
Here's my code:
public class Test extends JFrame
  public static void main(String argv[])
    JFrame test = new JFrame("nuts");
    test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    test.setSize(700, 700);
    Container content = test.getContentPane();
    test.setVisible(true);
    test.setAlwaysOnTop(true);
    // create object called 'maze' here
    maze.paint(content.getGraphics());
}I don't mean to be rude or anything; nor do I rightly understand what I've done wrong. I'm not trying to leech off anyone; I've honestly tried to figure this out, and I can't. So I'm really hoping someone can please help me. Thank you!

Similar Messages

  • How do I delete movies from iTunes library? I have moved them to the iCloud and now only seem to have the option to hide the icon in iCloud.  I am sure I chose poorly at the 'keep file' window.  Please help. My Brain hurts- 18   movies need to go-.

    How do I delete movies from iTunes library? I have moved them to the iCloud and now only seem to have the option to hide the icon in iCloud.  I am sure I chose poorly at the 'keep file' window.  Please help. My Brain hurts… 18 plus movies need to go….  Thank you.

    Instead of removing the music from the cloud or the iTunes library why not shuffle your music using a Smart Playlist which excludes the holiday music, or tracks that are not checked. For example, use this very simple Smart Playlist:

  • My ipad mini is not syncing music onto in, my ipad has been replaced to see whether the issue is to do with the ipad but its still not working. i have a a windows PC please help thanks

    my ipad mini is not syncing music onto in, my ipad has been replaced to see whether the issue is to do with the ipad but its still not working.
    ive tried everything and ive been to the store which was when i was given a new ipad mini. i have a a windows PC please help thanks

    Are you attempting to sync music from your iTunes Music Library on your PC?
    What options do you have set on the Music Tab for your iPad in iTunes?
    What happens when you sync?
    Any error messages?

  • My ipod 3rd generation is not recognized by windows/itunes,please help

    My ipod 3rd generation is not recognized by windows/itunes,please help. Have tried restoring a number of times but did not work, any suggestions?thanks

    Start with this Apple support document.
    http://support.apple.com/kb/TS1369
    B-rock

  • Hello My ipads Power button is not working properly when I press it once it shows option to turn off instead of locking and some other display problems like it suddenly lockes down or display disappears ...Please help. Thank You

    Hello My ipads Power button is not working properly when I press it once it shows option to turn off instead of locking and some other display problems like it suddenly lockes down or display disappears ...Please help. Thank You

    Thanks for that information!
    I'm sure I will be calling AppleCare, but the problem is, they charge for the phone calls don't they? Because I don't have money to be spending to be on the phone with a support service.
    In other things, it seemed like the only time my MacBook was working was when I had Snow Leopard without the 10.6.8 update download that was supposed to be done to prepare for OS X Lion.
    When I look at the information of my HD it says that I have 10.6.8 but that was the install that it claimed to have failed and caused me to restart resulting in all of the repeated problems.
    Also, because my computer is currently down, and I've lost all files how would that effect the use of my iPhone? Because if it doesn't get fixed by the time OS 5 is released, how would I be able to upgrade?!

  • I shot a video clip(800MB) using my iPhone4s but could not copy to my PC (windows XP),please help me

    I shot a video clip(800MB) using my iPhone4s but could not copy to my PC (windows XP),please help me

    Limitation of XP, videos over 500MB's can't be imported using Camera/Scanner wizard. Try transfering these Videos directly from your phone by selecting them in My Computer and dragging or copying the movie files to your computer's hard drive.

  • Can't download latest iTunes on Windows 7, please help?

    Hi,
    I'm having trouble downloading the lastest version of iTunes from the apple website.
    I clicked download iTunes etc and then got the itunessetup thingy, so I tried installing it but within seconds the wizard does to the end page and says:
    'ITunes installer completed.
    The installer encountered errors before itunes could be configured. Errors occured during installation. Your system has not been modified.
    Please run the installer again, or click finish to exit.'
    I have tried installing it several times and keep getting the same issue. I also uninstalled everything I have from Apple on my laptop and tried installing iTunes again then with no luck.
    It's really frustrating me now and i have no idea what to do. I've tried searching this issue but other people have posted about different problems to this one so I dont know how to fix it. Help please?
    Thanks

    new to Windows 8, please help me.
    Coming from Windows 7?  It is quite analogous, especially if you were a keyboard user.  Ctrl-Esc (or press and release Win) shows you the equivalent of the Start Menu, which is now called the Start Screen.  In W7 once you brought up the
    Start Menu you may have been aware that you could either click on pinned items, click on pinned Taskbar buttons, click on Desktop shortcuts, OR... do some typing to bring something up from your installed applications.  Well, in W8 we could do the first
    and the last completely the same and now in W8.1.1 we can do all of those things.  There are also new options which can keep you mostly oblivious of the Start Screen if you would prefer to do that.
    But to answer your specific example, after you see the Start Screen (or All apps view of it) just start typing P O
    FYI
    Robert Aldwinckle

  • Boot Camp won't let me remove my windows partition, please help

    I am trying to remove my windows partition and boot camp won't let me. It gives me a message +" The startup disk must be formatted as a single Mac OS Extended (Journaled) volume or already partitioned by Boot Camp Assistant for installing Windows."+ Please help!!!!!

    Use the Disk Utility to delete it and resize the partition immediately above of it so it takes up the released space.
    (51550)

  • I have been trying to put some of my music and artwork, on youtube. Youtube says you need an encoder to upload music. But the problem is the only encoders available are for windows. Please help, thank you

    I have been trying to put some of my music and artwork, on youtube. Youtube says you need an encoder to upload music. But the problem is the only encoders available are for windows. Please help, thank you

    The formats YouTube supports can be found here:
    http://www.google.com/support/youtube/bin/answer.py?answer=55744
    Since YouTube supports AAC, the file format iTunes uses by default, it's probable you don't need any sort of converter.
    If you continue to have problems with uploading to YouTube, I'd suggest you ask for assistance in their forums:
    http://www.google.com/support/forum/p/youtube?hl=en
    Regards.

  • HT204074 My PC is not getting authorized & I am not able to sync my I pad with my PC any more nor Im able to install any app. I recently reinstalled my windows. Please help. I tried authorizing with my ID but it still shows the message computer is no long

    My PC is not getting authorized & I am not able to sync my I pad with my PC any more nor Im able to install any app. I recently reinstalled my windows. Please help. I tried authorizing with my ID but it still shows the message computer is no longer authorized.

    It may think it's a new computer.
    Sync Your iOS Device with a New Computer Without Losing Data
    http://www.howtogeek.com/104298/sync-your-ios-device-with-a-new-computer-without -losing-data/
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive
    https://discussions.apple.com/docs/DOC-3141
     Cheers, Tom

  • Windows uninstalled itself? or magically disappeared...please help

    ok, so about 3 or 4 months ago, my brother installed windows 7 proffesional on my macbook pro with snow leopard via bootcamp. everything was fine until yesterday, i was browsing the web and windows just shut down my computer. i thought that was weird and just started up my computer again, and upon hearing the start up chime, i help the alt key (because my default start up is my mac os x). now normally when i hold the alt key, two hardrives appear, one labeled macintosh and one labeled windows. When i held the alt key this time, only the Macintosh appeared. I logged into my mac osx then and went to system prefs and chose my default startup to be windows (because i can still find the windows hard drive in my finder and all the files i had on my windows). i did this and this message appeared "No bootable device - - please insert boot disk and press any key to continue".
    Does this mean my windows just randomly uninstalled? has this happened to anyone else and more importantly, does this have a fix? this is really annoying and i need my windows for some of my daily tasks on the computer. please help.

    thanks for your help, but when i inserted the windows disk, i pressed "any key" like it said and nothing happened. Still having trouble with this after a week of attempting solutions.

  • How to change background color in a window? Please help.

    Please help me to set background color to my window that includes some panels components.
    I have tried
    content.setBackground(Color.green); and
    frame.setBackground(Color.RED);
    but nothing works?
    Please what should I change in my code? Thanks already in advance for helping!!
    Main parts of my code:
    public void addComponentToPane(Container allComponents) throws IOException
    definePanels();
    allComponents.setLayout(new BoxLayout(allComponents, BoxLayout.Y_AXIS));
    allComponents.add(panel_introduction);
    allComponents.add(panel_n);
    allComponents.add(panel_resultTitle);
    allComponents.add(panel_w);
    allComponents.add(panel_testing);
    allComponents.setVisible(true);
    public static void main(String[] args) throws IOException
    try {
    GraphicsDevice device;
    Container content;
    JFrame frame = new JFrame("ImageOrder");
    device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    device.setFullScreenWindow(frame);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SwingApplication app = new SwingApplication();
    content = frame.getContentPane();
    content.setBackground(Color.green);
    app.addComponentToPane(content);
    frame.setVisible(true);
    finally {
    System.out.println("helle");
    }

    import java.awt.Color;
    import javax.swing.*;
    class Test extends JFrame {
         public Test( ){
              getContentPane().setBackground(Color.RED);
              pack();
              setSize(500, 500);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] argv) {
              new Test().setVisible(true);
    }

  • Disappear login. Please HELP!

    Hi, i have a Macbook 13'' (one of the previous gen. black) with OS X Leopard with i believe 10.5.8
    I'm having a similar problem as:
    http://discussions.apple.com/message.jspa?messageID=8106830
    and
    http://discussions.apple.com/message.jspa?messageID=8053014
    My login disappeared and I only have "Other..."
    a few differences though is that for some reason it takes about 3 minutes or so get to the login box, and mine failed to boot back up properly from sleep mode (lid closed then reopened later, so i hard reset)
    It also takes about as long when i tried to boot off my Leopard install disc.
    Unlike jatoskep it actually shows my account (which i named Home) to change the password.
    Now here comes the problem. I read the solution V.K. proposed and tried enabling my root account in Single User mode, which didnt work. So i booted from disc and changed the password to the root account. Then came a window that said something about that this does not change the keychain login password or something... Anyway, i exit and boot from my OS X 10.5.8 and try to log in as root (Name: "root" (w/o the " " of course)) but after like going slightly dim as its trying to log-in, it eventually fails.
    Oh and in Single User Mode, it says that my drive "Home" is "OK" (not sure what that means)
    Am i doing something wrong or is there some bigger issue? The lag time in booting concerns me.
    I have not installed anything new in the past few months, and had not touched any system preferences or setting at all either.
    Someone told me that it maybe my problem with my harddrive considering the excessive boot time.
    PLease help!

    Make sure that you do not block cookies.
    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    *https://support.mozilla.org/kb/Cannot+log+in+to+websites
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode

  • Boot Camp: Seagate External Drive not Recognized in Windows Explorer -- PLEASE HELP!

    I'm running in Boot Camp and using a Seagate Free Agent GoFlex external drive as both a Time Machine backup on the Mac OS, as well as a storage unit to exchange files. However, whenever I plug my external drive into my computer while running Windows, it does not show up in the Computer tab under "Devices With Removable Storage", like it should. It does show up on the "Safely Remove Hardware and Eject Media" button in the bottom right hand corner, and it appears as a "Startup Disk" in the Boot Camp Control Panel, so I know that it isn't a cable or USB input issue. Please help me get it to appear as a Device in the Windows Explorer. I need to exchange files from my Mac OS to my Windows OS. Thank you in advance for the help.

    I did it but i could not install tool from the dvd. As i said, i can still boot up windows xp i just needs to re-install the service tool.
    The drivers are working properly.

  • TS1369 itunes no longer sees my devices. But I can still see them in windows. Please help

    itunes no longer sees my devices. But I can still see them in windows. Please help

    Try
    iOS: Device not recognized in iTunes for Windows
    I would start with               
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    or               
    Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    New cable and different USB port?
    Runs this and see if the results help with determine the cause
    iTunes for Windows: Device Sync Tests
    Try on another computer to help determine if computer or iPod problem

Maybe you are looking for