Simon game. buttons wont flash... help!

This is a simple "Simon" memory game, produced in GUI...........
The main(); invokes the FIRE(); which generates random numbers , which in turns invokes one of four COLOR methods, red(), green(), yellow(), blue(); .... These methods flash one of the four buttons and are assigned their own values. when they are invoked, they pass that value to Pattern();
Pattern (); fills an array with the random values passed from the color methods, As well as compares users entry against the array and IF user entry is accurate then increase difficulty++
(Pattern method has poor logic in it. I would like tips on this.)
PROBLEM: it executes nearly perfect the first time the code cycles. After that the buttons no longer flash when the FIRE(); invokes COLOR(); methods.
THANKS IN ADVANCE FOR YOUR HELP.
import java.io.File;
   import java.io.IOException;
   import javax.sound.sampled.AudioFormat;
   import javax.sound.sampled.AudioInputStream;
   import javax.sound.sampled.AudioSystem;
   import javax.sound.sampled.DataLine;
   import javax.sound.sampled.LineUnavailableException;
   import javax.sound.sampled.SourceDataLine;
   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import java.util.*;
    public class Simon extends JFrame implements MouseListener,ActionListener
      //static int pat=1;
      private static final int     EXTERNAL_BUFFER_SIZE = 128000;
      static JButton but1 = new JButton("Green");
      static JButton but2 = new JButton("Blue");
      static JButton but3 = new JButton("Orange");
      static JButton but4 = new JButton("Red");
      static JPanel pane1 = new JPanel();
      static JPanel pane2 = new JPanel();
      static JPanel pane3 = new JPanel();
      static JPanel pane4 = new JPanel();
      static JPanel pane5 = new JPanel();
      static JButton but5 = new JButton("Start");
      //static JLabel lab1 = new JLabel("Simon Says");
      Container con = getContentPane();
      static File soundFile = new File("hiho.wav");
      static File utopia = new File("utopia.wav");
      static File cowbell = new File("cowbell.wav");
      static File slap = new File("sound16.wav");
      static int G1=1,B2=2,Y3=3,R4=4;
      static int[] array = new int[256]; // maximum value
      static int difficulty = 3; //initial value
      static int count;
      static int x=0;
      static boolean click=false;
       public Simon()
         super("Simon Says");
         con.setLayout(new BorderLayout());
         con.add(pane5,BorderLayout.CENTER);
         con.add(pane4,BorderLayout.NORTH);
         con.add(pane3,BorderLayout.SOUTH);
         con.add(pane2,BorderLayout.EAST);
         con.add(pane1,BorderLayout.WEST);
         pane1.add(but1);
         pane2.add(but2);
         pane3.add(but3);
         pane4.add(but4);
         pane5.add(but5);
         but1.addMouseListener(this);
         but2.addMouseListener(this);
         but3.addMouseListener(this);
         but4.addMouseListener(this);
         but1.addActionListener(this);
         but2.addActionListener(this);
         but3.addActionListener(this);
         but4.addActionListener(this);
         but5.addActionListener(this);
       public static void main(String[]args)
         JFrame af = new Simon();
         af.setSize(275,135);
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         af.setLocation( (screenSize.width - af.getWidth())/2,
            (screenSize.height - af.getHeight())/2 );
         af.setVisible(true);
         af.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         af.setResizable(false);
         but1.setContentAreaFilled(false);
         but1.setOpaque(true);//enabling button to changed with mouse events.
         but2.setContentAreaFilled(false);
         but2.setOpaque(true);
         but3.setContentAreaFilled(false);
         but3.setOpaque(true);
         but4.setContentAreaFilled(false);
         but4.setOpaque(true);
         but1.setBackground(Color.darkGray);
         but1.setForeground(Color.WHITE);
         but2.setBackground(Color.darkGray);
         but2.setForeground(Color.WHITE);
         but3.setBackground(Color.darkGray);
         but3.setForeground(Color.WHITE);
         but4.setBackground(Color.darkGray);
         but4.setForeground(Color.WHITE);
            // everytime the pattern fires a button it invokes a method which
            // recieves an int ... fills an array with digits. and before the int
            // is assigned a subscript a variable is incremented so the array continues
            // to cycle. 
            //store the last pattern in an array then, and do a check if they match generate new pattern.
         FIRE();
       public static void FIRE()
         for(x=0;x<difficulty;++x)
            double rnd = Math.random()*10;
            if (rnd<2.5)
               play(soundFile);   
               green();
            else if (rnd>=2.5&&rnd<=5.0)
               play(utopia);
               blue();
            else if (rnd>5.0&&rnd<=7.5)
               play(cowbell);
               yellow();
            else //if (rnd>7.5);
               play(slap);
               red();
         if(x==difficulty)
            count=0;
       public static void green()///////////////////////////////////////////////////////
         but1.setBackground(Color.GREEN);
         but1.setForeground(Color.WHITE);
         try
            Thread.sleep(200);
             catch(InterruptedException e){}
         but1.setBackground(Color.darkGray);
         but1.setForeground(Color.WHITE);   
         try
            Thread.sleep(200);
             catch(InterruptedException e){}
         Pattern(G1);
       public static void blue()////////////////////////////////////////////////////
         but2.setBackground(Color.BLUE);
         but2.setForeground(Color.WHITE);
         try
            Thread.sleep(200);
             catch(InterruptedException e){}
         but2.setBackground(Color.darkGray);
         but2.setForeground(Color.WHITE);
         try
            Thread.sleep(200);
             catch(InterruptedException e){}
         Pattern(B2); 
       public static void yellow()///////////////////////////////////////////////////////
         but3.setBackground(Color.ORANGE);
         but3.setForeground(Color.WHITE);
         try
            Thread.sleep(200);
             catch(InterruptedException e){}
         but3.setBackground(Color.darkGray);
         but3.setForeground(Color.WHITE);
         try
            Thread.sleep(200);
             catch(InterruptedException e){}
         Pattern(Y3); 
       public static void red()//////////////////////////////////////////////////////////
         but4.setBackground(Color.RED);
         but4.setForeground(Color.WHITE);
         try
            Thread.sleep(200);
             catch(InterruptedException e){}
         but4.setBackground(Color.darkGray);
         but4.setForeground(Color.WHITE);
         try
            Thread.sleep(200);
             catch(InterruptedException e){}
         Pattern(R4);
       public void mousePressed(MouseEvent e)////////////////////////////////////////////////////////////////
         //System.out.println(" Count Equals before Fire()"+count);
         Object source = e.getSource();
         if (source==but1)
            click = true;
            but1.setBackground(Color.GREEN);
            but1.setForeground(Color.WHITE);
            play(soundFile);
            Pattern(G1);
         if(source==but2)
            click = true;
            but2.setBackground(Color.BLUE);
            but2.setForeground(Color.WHITE);
            play(utopia);
            Pattern(B2);
         if (source==but3)
            click = true;
            but3.setBackground(Color.orange);
            but3.setForeground(Color.WHITE);
            play(cowbell);
            Pattern(Y3);
         if (source==but4)
            click = true;
            but4.setBackground(Color.RED);
            but4.setForeground(Color.WHITE);
            play(slap);
            Pattern(R4);
       public void mouseReleased(MouseEvent e)/////////////////////////////////////////////////////////////
         Object source = e.getSource();
         if(source==but1)
            but1.setBackground(Color.darkGray);
            but1.setForeground(Color.WHITE); 
         else if (source==but2)
            but2.setBackground(Color.darkGray);
            but2.setForeground(Color.WHITE);
         else if (source==but3)
            but3.setBackground(Color.darkGray);
            but3.setForeground(Color.WHITE);
         else if (source==but4)
            but4.setBackground(Color.darkGray);
            but4.setForeground(Color.WHITE);
       public static void Pattern(int A)/////////////////////////////////////////////////////////////
         if (x<difficulty)
            array[count]=A;
            System.out.println("Randomly generated array position "+count+"'s value is, "+A);
            ++count;
         if (x==difficulty)
            System.out.println(".....User entry at array position "+count+"'s value is, "+A);       
            if (array[count]==A&&count==difficulty-1) //if user entry is correct and the array has reached
               NEXT();
                                                                 //array.length then invoke NEXT();    
            if (A!=array[count]/*&&count<difficulty*/&&count!=0)//poor logic: at anytime if array[count] is not equal to user entry, LOSE();        
               LOSE();
            if (click==true)       
               count++; 
         click =false;                
       public static void LOSE()
         System.out.println("YOU LOSE");
         System.exit(0);
       public static  void NEXT()
     //     String[] s = null;
         System.out.println("NEXT LEVEL");
         ++difficulty;
         count=0;
         x=0;
           // Simon.main((s = new String[] {"N"}));
         FIRE();
       public static void play(File soundFile)////////////////////////////////// AUDIO PLAYER
         AudioInputStream     audioInputStream = null;
         try
            audioInputStream = AudioSystem.getAudioInputStream(soundFile);
             catch (Exception e)
               e.printStackTrace();
               System.exit(1);
         AudioFormat     audioFormat = audioInputStream.getFormat();
         SourceDataLine     line = null;
         DataLine.Info     info = new DataLine.Info(SourceDataLine.class,audioFormat);
         try
            line = (SourceDataLine) AudioSystem.getLine(info);
            line.open(audioFormat);
             catch (LineUnavailableException e)
               e.printStackTrace();
               System.exit(1);
             catch (Exception e)
               e.printStackTrace();
               System.exit(1);
         line.start();
         int     nBytesRead = 0;
         byte[]     abData = new byte[EXTERNAL_BUFFER_SIZE];
         while (nBytesRead != -1)
            try
               nBytesRead = audioInputStream.read(abData, 0, abData.length);
                catch (IOException e)
                  e.printStackTrace();
            if (nBytesRead >= 0)
               int     nBytesWritten = line.write(abData, 0, nBytesRead);
      //       line.drain();
      //          line.close();
         //System.exit(0);
       private void printUsageAndExit()
         out("SimpleAudioPlayer: usage:");
         out("\tjava SimpleAudioPlayer <soundfile>");
         System.exit(1);
       private void out(String strMessage)
         System.out.println(strMessage);
       public void actionPerformed(ActionEvent e)//OVERRIDDEN INTERFACE METHODS
       public void mouseClicked(MouseEvent e)
       public void mouseEntered(MouseEvent e)
       public void mouseExited(MouseEvent e)
   }

In the future, Swing related questions should be posted in the Swing forum.
You don't use the Thread.sleep(...) method in the GUI Event Thread, it prevents the GUI from responding to events and repainting itself.
Use a Swing Timer to schedule the frequency of whatever you are doing.

Similar Messages

  • Adding Custom Buttons to Flash Help Skin

    Hi.. Can anyone suggest me how to add custom buttons to
    FlashHelp Skin. I know we can do this in WebHelp don't know how to
    do that in FlashHelp. Any help is greatly appreciated. Thank
    you..

    In a VI go to Edit >> Run-Time Menu to change the menu seen to the user when the VI is running.
    To handle when a selection is made use the Event structure.  There are are several shipped examples in the Example Finder.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Menu button wont work! pleeeease help!

    my i pod mini's menu button wont work.
    i'll push it and it doesn't respond.
    and i cant reset it because i need to use the menu button.
    also...the backlight will come on at random times lyk even when im not using it. and it beeps sometimes too. just really loud beeps, not through the headphones but the actual i pod.
    i dont know whats going on.
    and i need to use my menu button.
    please help me. i need answers!
    please and thank you.
    <333 a L e x x<br>
    windows   Windows XP  

    Very likely it is a hardware issue (exactly same as mine). I am afraid to say that you need to send it for repairing. You will get a replacement if your iPod mini still under the warranty

  • I can't install any app because my install button wont work pls help

    I can't install any app because my install button wont work pls help, what shall I do?

    - What do you mean it does not work? Could it be that the app ere not compatible with your model iPod and its iOS?
    - Try going to Settings>Store and sign out and sign back in.

  • Using "Flash Help" to help make flash game?

    Hello,
    I've noticed the other day that in Flash, the "Flash Help (F1)" found under "Help" is licensed under "Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License".  The resources found on adobe.com in the Flash Development Center is also licensed with this.
    The license state:
    " You are free:
        * to Share — to copy, distribute and transmit the work
        * to Remix — to adapt the work
    Under the following conditions:
    Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
    Noncommercial — You may not use this work for commercial purposes.
    Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one."
    - CC License
    I'm trying to learn flash so I can make flash games.  I plan to get them sponsored by game portals and attach them to MochiAds--so technically this would be commercial, yes?
    So does this mean I CAN'T use "Flash Help" or any of the resources found in adobe's Flash Development Center to learn how to use actionscripts?
    Of course I don't plan to bluntly copy-paste codes, but it would be nice if I could adapt and learn how things work.  Sometimes I get stuck and I need a reference...  The last thing I'd want is to get into some copyright trouble =/
    Sorry if this post is out of place.  I tried to ask in Customer Support days ago but I get the feeling that they've ignored me.
    Any extra advices are welcome.
    Thank you,
    Jane

    What is with all the folks asking "copyright" questions lately? Are you all in some class or something? I am not a copyright lawyer so don't take anything I say as the absolute truth, but I have had a long standing interest in these issues...
    Anyways copyright is not an absolute right, there is an important part of copyright law called "fair use" and it is important. Of course it is also the source of a lot of disagreements and law suits...
    A clear case of infringement would be if you tried to just take the Flash help and publish your own "learn actionscript" help book or website.
    But given that the help documentation is meant to teach you how to use the product it seems that it would be clearly within fair use to use it to learn how to use the product.
    And while the US courts have not been particularly intelligent about technical innovation -- often granting patents and copyright to very basic code, while not protecting truly innovative and clever invention -- the argument that the basic instantiation of a class and invocation of its methods, properties, and events, is pretty clearly the only way to do these things. Adobe would have no reason -- in fact they would have quite the opposite -- to pursue a claim against somebody who used actionscript.
    Given the absurdity of the US courts (if here is where you be) just change the names of the variables from the samples and you are most likely fine since it would confuse them.

  • Creating a minimize and restore button in flash.. help :D

    hi,
    is there a way in flash to be a able to create a minimize and a restore button in flash,, and
    is it also possible to remove my title bar?
    tnx in advance..

    Oh thank you so much!! I have spent days looking for this and could not figure out why the code did not work. My professor has been out sick so he has not responded to emails since the end of last week. Now one last thing is that when I click test movie my polygon object is in stop mode meaning it is not moving. I have to click play for it to move. Is there anything I can add to my code so that when I hit test movie and the test window pops up the polygon is automatically playing without me having to hit the play button first?

  • Power button wont work

    okay so about 10 minutes ago i was sitting down and had my phone charging in my lap, i didn't do anything differently and then all of a sudden my screen flashed on then off then on and off and so on about 5 or 6 times rapidly, now my power button wont work at all, no matter what, i have taken out my battery and put it back in but thats all i can think of, any ideas?

        Good morning, jcmorgan17. Thanks for trying all the suggestions from your fellow customers. I'm confident that if you made it into the store, their hands-on evaluation was able to help determine if the phone needed to be replaced through your warranty http://vz.to/uyYF0o or if there may have been some prior damage and insurance http://bit.ly/07CrqPK or other replacement options were needed. If you were unable to visit the store, please call 866-406-5154 from an alternate line so we can help with finding the best solution as quickly as possible.
    Thank you
    JenniferH_VZW
    Please follow us on Twitter @vzwsupport

  • Can't watch video and play games that require flash player

    I'm using windows7 family premium version
    internet explorer 10 last version 10.0.5
    exploitation system 64 bytes
    flash player verson 11..700.202 the latest one
    So as i say can't watch video and play games that require flash player, they keep asking me to install flashplayer... i did everything i read in the forums, unistall it, clean the memory, reinstall it, disabe active x etc... but still have the problem.
    More specific about my problem is that: let's say that i'm trying to look at you tutorial video under thi forum  Re: How do I fix Windows permission problems with Flash Player? i'm just seeing a black screen.  So I'm able to guess where is the play button so when i push on that place, i can hear the sound of that video.  Second step guessing where is the  enlarge  button, and when the screen is enlarged, magic i can see and hear the video.... So you figure that it's impossible to use my computer like that and guess right all the time, so....
    Second fact, it seems that bug happened after an update (windows or explorer) and i even talk with a microsott tech who was not able to resolve it... But if i'm  undoning  the update and go back to a prior image, i have no problems with flash player anymore... it' been moths that i'm delaying my updates cause i cannot find any solutions.... So Please please please, help me .... don't know what's the problem is and i'm not a pro, don't know what to do.  (Excuse my english it's my second language)
    Thank you

    The first thing I'd try is updating your video driver.
    Windows: how do I update the device driver for my video/display adapter?
    If you still have problems and since you're using Windows 7 x64, please check to see if you have the following Windows update installed:
    KB2670838 – Platform Update for Windows 7 x64
    If so, please uninstall it and try Flash Player out again.

  • Game center wont recognise my apple ID but works with other accounts? On mountain Lion?

    Game center wont recognise my apple ID but works with other accounts? On mountain Lion? i tryed to test out the new game center on mountain lion and it will not let me log in no message pops up or forgot your password but when i try other accounts it works fine help please i really want to use game center for mountian lion!

    Game center wont recognise my apple ID but works with other accounts? On mountain Lion? i tryed to test out the new game center on mountain lion and it will not let me log in no message pops up or forgot your password but when i try other accounts it works fine help please i really want to use game center for mountian lion!

  • The Flash Help Search doesn't work

    Do I need to reinstall my flash ? I installed flash 8
    professional on my machine about a month ago. i have just noticed
    that the search button in the help section doesn't do anything.
    what should i do?
    All the help content is there but the only way i can find
    help on the topic I need is by searching through all the books
    which is obviously not very efficient.

    I was having the same problem on one of my Macs. I resolved it by removing the two help preference files in my ~/Library/Preferences folder.
    Kirk

  • How to make a fullscreen button for Flash Catalyst?

    Hey everyone.  I really hope someone can help me with this.  How can I make a fullscreen button in Flash Professional that would make my Flash Catalyst project go fullscreen?

    I'm sorry I really don't know Flash Catalyst as much as I'd like to. Designing interfaces is left up to me, no designers at my agency use Catalyst. Though this is the Flash forum so that's as much as I can tell you. I didn't know Catalyst didn't support basic scripts (I thought I read that it did).
    Ultimately, for a very cheap price you can do something like go to http://www.lynda.com/ and buy a membership. Dirt cheap compared to what you get. They offer many courses on all this stuff and I'm sure your answer would lie in one of the (nicely broken up by subject) video training videos.
    Just searching for Catalyst brings up a bunch of courses:
    http://www.lynda.com/search?q=catalyst&x=0&y=0
    edit:
    For instance I watched the essential CS5.5 training and I saw in 2 minutes flat that when you click on a button you should have an "Interactions" panel that lets you do things. If they didn't put fullscreen as an interaction that's another thing but I'm just pointing out it's very easy to learn how to do all sorts of things in video training. If you do not want to purchase a membership there just find a video you think would have the info in it and I'll watch it and let you know if it told me how to do it, and how to do it.

  • Hi, I have an iPod touch 5th generation which i got about 10 months ago and now my sound is not working. for example my music isn't playing nor are any of my game sounds. Someone help please.

    Hi, I have an iPod touch 5th generation which i got about 10 months ago and now my sound is not working. for example my music isn't playing nor are any of my game sounds. Someone help please.

    No sound form :
    - Speaker?
    - Headphones?
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.             
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                      

  • I go to touch an app or game button on my iPhone and the screen blinks like its trying to open, but nothing happens. Why and what do I do?

    I go to touch an app or game button on my iPhone and the screen blinks like its trying to open, but nothing happens. Why and what do I do to fix it?

    Are there any apps in the muti-tasking bar? If the app closed unexpectedly and appeared in the muti-tasking bar, end it. Double tap the home button and then hold the app until it starts to wiggle then tap the minus at the top left at the app (if you want, end all the remaining apps)  try opening them now. Hope this helps! :)

  • How to link an image to a button in Flash Builder 4

    I am new to Flash Builder 4 and have trouble to link an image to a button in Flash Builder 4.
    For example, I want an image of a round green button to replace the default retangle button in Flash Builder 4.
    Can anyone help me up?
    Thanks

    You could also use the mx:Image control and just add a click event handler:
    function(){return A.apply(null,[this].concat($A(arguments)))}
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx"
            width="500" height="400">
        <fx:Script>
            <![CDATA[
                import mx.controls.Alert;
                protected function image1_clickHandler(evt:MouseEvent):void {
                    Alert.show("You clicked the image");
            ]]>
        </fx:Script>
        <mx:Image source="http://helpexamples.com/flash/images/image1.jpg"
                click="image1_clickHandler(event);" />
    </s:Application>

  • I Drop My Ipod Alot And Now It Wont Charge It Wont Show My Notifications Even Doe They Are On My Home Button Wont Work Just A few Times But Thats It.and when on my vine i doesnt let me hear my vines idk why

    PLEASEE HELP I Drop My Ipod Alot And Now It Wont Charge It Wont Show My Notifications Even Doe They Are On My Home Button Wont Work Just A few Times But Thats It.and when on my vine i doesnt let me hear my vines idk why

    You broke it, you will need to get it serviced or replaced. The drop voided your warranty so you would have to do an out-of-warranty replacement with Apple.
    Please don't type in headline style, i.e. capitalizing every word.

Maybe you are looking for