Stop Gate game

Hi, I am a student trying to program a game that has a checkerboard pattern and will be two players with one being a computer. The object is lay down "dominoes" which is a square panel and one more to the right of it (horizontal). The computer will take up two panels with each panel being above or below the other (vertical). When there is no more moves available for a player, that player loses. Each player is a different color.
First off, I have a checkerboard pattern drawn but at first I thought about using actionPerformed with some sort of button but now I am thinking of using mouseClicked and somehow having it read what panel it is in then fill that in with the one to it's right. Does that sound like the easiest plan of attack? Without being super advanced of course.
Here is my code so far:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class StopGate2 extends JFrame
  final int ROWS = 8;
  final int COLS = 8;
  final int GAP = 2;
  final int NUM = ROWS * COLS;
  int x;
  JPanel pane = new JPanel(new GridLayout(ROWS, COLS, GAP, GAP));
  JPanel[] panel = new JPanel[NUM];
  Color color1 = Color.WHITE;
  Color color2 = Color.GRAY;
  Color tempColor;
  public StopGate2()
    super("StopGate2");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    add(pane);
    for(x = 0; x < NUM; ++x)
      panel[x] = new JPanel();
      pane.add(panel[x]);
      if(x % COLS == 0)
         tempColor = color1;
         color1 = color2;
         color2 = tempColor;
      if(x % 2 == 0)
        panel[x].setBackground(color1);
      else
        panel[x].setBackground(color2);
  public static void main(String[] arguments)
    StopGate2 frame = new StopGate2();
    final int SIZE = 300;
    frame.setSize(SIZE, SIZE);
    frame.setVisible(true);
}

I added the mouseListener to each panel but I am not able to pass the panel number that is being clicked.
Here is my code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class StopGate2 extends JFrame implements MouseListener
  final int ROWS = 8;
  final int COLS = 8;
  final int GAP = 2;
  final int NUM = ROWS * COLS;
  int x;
  JPanel pane = new JPanel(new GridLayout(ROWS, COLS, GAP, GAP));
  JPanel[] panel = new JPanel[NUM];
  Color color1 = Color.WHITE;
  Color color2 = Color.GRAY;
  Color color3 = Color.YELLOW;
  Color tempColor;
  public StopGate2()
        super("StopGate2");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    add(pane);
    for(x = 0; x < NUM; ++x)
      panel[x] = new JPanel();
      pane.add(panel[x]);
          panel[x].addMouseListener(this);
      if(x % COLS == 0)
         tempColor = color1;
         color1 = color2;
         color2 = tempColor;
      if(x % 2 == 0)
        panel[x].setBackground(color1);
      else
        panel[x].setBackground(color2);
  public void mouseClicked(MouseEvent e)
       int whichButton = e.getButton();
     if(whichButton == MouseEvent.BUTTON1)
          System.out.println(x);
  public void mouseEntered(MouseEvent e)
       //System.out.println("paint");
  public void mouseExited(MouseEvent e)
  public void mousePressed(MouseEvent e)
  public void mouseReleased(MouseEvent e)
  public static void main(String[] arguments)
    StopGate2 frame = new StopGate2();
    final int SIZE = 300;
    frame.setSize(SIZE, SIZE);
    frame.setVisible(true);
}Encephalopathic, I am not clear on how I could do pass the MouseEvent variable.

Similar Messages

  • How do i stop a game from jumping or turning itself off when i am playing on it?

    When i am playing on temple run 2, subway surfers and the odd occassion candy crush, the game is slow to when i am directing them to move or they are just turning themselves off. Does anyone know why this is or how i can stop it? I have tried turning ipod off and on again and deleteing the app and re-installing it and nothing is happening.
    Any help would be great. Thanks.

    Try This...
    Close All Open Apps...  Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430
    Also consider Deleting any Apps you have Purchased / Downloaded but you now never use..

  • Sound stops during games

    Randomly my sounds stops during most of my games.  Clash of clans my sound will fade in and out like its trying to work properly, but other apps are just muted completely.  If im listening to music while playing a game, it seems to happen more often.  ALL sound is stopped, i have to exit my app to turn the music back on.  This happened after i synced some music.  It was TERRIBLE, but i managed to sync it 3 or 4 more times to try and correct the problem, it helped but didnt fix it.  One day my sound wouldnt even adjust.  Something is seriously wrong with this OS.  This has been a problem since iOS7.  And i was syncing my wifes new Justin Timberlake, apparently the iPod hates him as much as i do.

    NoSound problem with headphones? With speaker?
    If only with headphones have you tried another pair of headphones?
    Try:
    - 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                                      

  • How can I stop the game that is on my Firefox homepage?

    How do I stop the annoying game that is on my Firefox home page?

    # Type ''about:config'' into the address bar and press Enter.
    # To bypass the warning, press the big button labeled "I'll be careful, I promise!".
    # In the search box, paste ''browser.aboutHomeSnippets.updateUrl''
    # In the search results, double-click ''browser.aboutHomeSnippets.updateUrl''
    # In the "Enter string value" dialog, press the Delete key so that there's no text remaining, then press either Enter or the OK button. As a side-effect, only default tips will be displayed below the search box, because new ones won't be fetched from the web anymore.
    # Type ''about:support'' into the address bar and press Enter.
    # Click the Show Folder button. A Windows Explorer window with your profile folder opens. In that window, open the ''storage'' folder, then the ''persistent'' subfolder.
    # Exit Firefox.
    # Delete the ''moz-safe-about+home'' folder.

  • How do I stop constant Game Center popups?

    IPad 3, iOS 6. I am not interested in gaming community. I want to delete Game Center and stop all notifications. How can I remove my ID from GC? I logged out but that doesn't help. I turned off notifications, but that didn't help.

    YAHOO! - so to speak. That was it. The pref pane in Guest looked normal. So I went back (in full boot) and deleted any pref file I could find for AddressBook. Now I look normal . . .
    . . . and **** if that Sync w/ Yahoo! WAS CHECKED. I un-checked it.
    While I was searching for stuff to delete, I also found this weird pref file 'com.apple.yahoo.synctool.plist' . . .
    Can't find anything called a SYNCTOOL. Hopefully this will end the annoyance. Thank you very much for your insights and aid.

  • Ipod video stopped playing games

    can any one help i am not technical so please try not to baffle me. my ipod video played my games fine then for some unknown reason i just get a error message and it says to reinstall my games came some tell me how in simple terms. kind reguards and thanks for your help.

    If you're not very technical, the easiest way would be to wipe out everything on the iPod, and then reload everything back on.
    http://docs.info.apple.com/article.html?artnum=60983

  • Flash Player stops playing games after most recent update.

    My father uses the website PCHGAMES.COM, daily.  He loves to play bingo.  Earlier this week Flash Player updates itself and now PCHGAMES.COM, bingo will not play.  It would let you chose which room to go to, and play the movie before the game, but when it gets to loading the room and chose the bingo cards all you get is a RED X.  After coming over to see what the issue was, and following all solutions on Flash Player games, video, or audio don't work | Windows page... The only solution that works is #7. Disable Flash Player hardware acceleration.  Once I followed these instructions, the bingo game played fine as long as he did not leave that page or window.  If he got bored and went to play another game and then came back to bingo it would not work again.  Then I would have to come back over and do #7. Disable Flash Player hardware acceleration, except this time it would be checking the box and Enable Flash Player hardware acceleration.  My father is disabled and doesn't understand why all of a sudden bingo will not work when it has been fine for 3 years.
    Currently his computer is using Windows Vista (32-bit), using IE Version 9.0.8112.16421, with Flash Player Version 11.1.102.63
    Is there any way to fix this other than having to come back to Adobe's site and enable or disable this checkbox every time he wants to play bingo?

    LW327, this is an issue that really annoys me! Laptop manufacturers produce their own 'custom' drivers that are actually, in most cases, exactly the same as generic drivers, except often years out of date! If there are actually any differences, then it's a few hooks into manufacturer installed programs, so installing a generic driver may, in the worst case, only cut down on some functionality with associated OEM supplied software.
    There are 2 ways around your problem to install the newest Intel driver:-
    1) Download the newest driver from Intel. Uninstall your current driver, reboot, and manually install the Intel one.
    2) Download the zip version of the Intel driver. Unzip it to a directory, then update your driver by picking the location where you unpacked the archive. This allows any checks that may scupper an install over the top of a custom driver to be avoided.
    Once you have the latest Intel driver installed, you'll get updates via Microsoft Update. There again, I just checked the Intel website and the latest G31/33 driver is dated May 2009, so installing it probably wont make any difference to your predicament. There again, the real issue here is that flash is messed up!

  • I put in my itunes gift card 2 of them with 10 or 15 dollars to my account and i never recieved my credits into my account. Note that this was a year ago and since i stopped buying games cam someone help me get this money back?

    I need help reclaiming my money.
    I never got my moneys worth

    After a year it may be too late for you to try and claim that a mistake has been made, but go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store. Perhaps there will still be something they can do to help you, though after all this time I doubt it.
    Good luck and regards.

  • Best method to stop game and make a 3,2,1 countdown on screen?

    Hi,
    Was wondering if I wanted to stop my game so that no input and all ai action seized what the best way to do it is, is there a way besides stop every listener and every timer and ai event?
    Also I want to kind of make a big 3,2,1 countdown appear in the middle of the screen, what is the best way to do that?? make the symbols and then going visible->invisible for each?
    Thanks

    One way you could probably weave in to stop everything in one shot is to have a boolean variable that you set true/false that is used for every event handler function or other function that might be activated.  Meaning the first line inside a function is a conditional to test the value of that boolean... that conditional being the gateway to the rest of the code.  But if you intend to truly shut down the works, then stopping all listeners and processing piece by piece would be your safest bet.
    There are a varety of ways you could do a countdown. Just using a textfield might suffice.  Or maybe you want something more graphical where a movieclip changes frames or something.  There really are too many options for you to need to ask... just think what you'd like to see and do it.

  • Wav play in my game but stops after some minutes

    I play wav files in my game and all is ok during first minutes, but then sound stops and game continue.
    Some idea?
    It happen in all my games :(:(:(
    Test phone: nokia 6600
    Many thanks

    Hessiess wrote:
    After the fan stops, can you re start it again by physically spinning the blades? If so, and as it is reasonably old, I would recommend replacing the fan.
    To test with a different OS, you could use a different live CD, i.e. Ubuntu/Fedora/Knoppix etx.
    Hi Hessiess. I tried that as well, the fan does not restart even if spinned by hand. Looks like there's no power flowing in it!
    The fan is just two years old, and it used to spin at an average of 2500 rpms, so the end of life should be far away. I keep the internals clean with compressed air, no dust bunnies anywhere
    I'll be testing with a live distro, thanks for the suggestion.
    Cheers.

  • HT5463 I'm using my iPhone for my wedding ceromony music will do not disturb also stop game notifications ?

    I'm using my iPhone for my wedding ceremony music will the do not disturb stop all game notifications coming through ? Thanks in advance

    You might want to just put it in airplane mode as well.
    I know DND does not block calls/notifications if the phone is actively being used (not in standby). I haven't experimented, so I'm not sure whether it will consider the phone "in use" if the music player is actively playing.

  • How to refresh my GUI in connect 4 game

    Hi all,
    I write an application of a beginner level of connect 4. It has a problem: I cannot reset/refresh the screen after I find a winner or tie. I wonder if someone here can give me a hand.
    Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class Connect4GUI extends JFrame
         private final int WIN_WIDTH=500;
         private final int WIN_HEIGHT=500;
         private JFrame frame;
        private JPanel panel_Center;
         private JButton[][] buttonsBoard;
         private int [][] chess;
         private JPanel panel;
        private JButton startButton;
         private JButton rePlayButton;
         private JButton exitButton;
        private static  String player1Name;
         private static  String player2Name;
         private static final int player1_ID=1;
         private static final int player2_ID=2;
        private String input;
         private boolean gameOver=false;
         private boolean playAgain=false;
         private static int steps=0;
    /********************constructor**************************************************/
    public Connect4GUI()
         playerInfo();
         showFrame();
         JOptionPane.showMessageDialog(null,"Press Start to start the game.");
    public void playerInfo()
         player1Name=JOptionPane.showInputDialog("Player 1 please enter your name.");
         player2Name=JOptionPane.showInputDialog("Player 2 please enter your name.");
    public void showFrame()
         setTitle("Connect 4");
         setSize( WIN_WIDTH,WIN_HEIGHT);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setLayout(new BorderLayout());
         JPanel panel_North=new JPanel();//show player info
         panel_North.setLayout(new FlowLayout());
         JLabel labelPlayer_1= new JLabel("player 1 is "+player1Name);
         JLabel labelPlayer_2= new JLabel("player 2 is "+player2Name);
         panel_North.add(labelPlayer_1);
         panel_North.add(labelPlayer_2);
         JPanel panel_South=new JPanel();//add several button
         panel_South.setLayout(new FlowLayout());
        //create buttons
         startButton=new JButton("Start");
         rePlayButton=new JButton("Replay");
         exitButton=new JButton("Exit");
        //button listern
         startButton.addActionListener(new myStartButton());
         rePlayButton.addActionListener(new myrePlayButton());
         exitButton.addActionListener(new myexitButton());
        //add buttons to the panel
         panel_South.add(startButton);
         panel_South.add(rePlayButton);
         panel_South.add(exitButton);
         panel_Center=new JPanel();//show the board
        panel_Center.setLayout(new GridLayout(6,7,10,10));//6x7 chess board
         buttonsBoard=new JButton[6][7];
         chess=new int[6][7];
             for (int r=0; r<6;r++)
                   for (int c=0;c<7;c++)
                        buttonsBoard[r][c]=new JButton();
                        buttonsBoard[r][c].setBackground(Color.yellow);
                        panel_Center.add(buttonsBoard[r][c]);
                        buttonsBoard[r][c].addActionListener(new mybuttonsBoard());//add actionListener
                    chess[r][c]=0;
         }//end for
         //construct the frame
        add(panel_North,BorderLayout.NORTH);
        add(panel_South,BorderLayout.SOUTH);
        add(panel_Center,BorderLayout.CENTER);
           setVisible(true);
    }//end showFrame()
    public boolean hasAWinner()
       boolean hasAWinner=false;
      //win at row
      for (int r=0;r<6;r++)
            for(int c=0;(c+3)<7;c++)
                    if(chess[r][c]==chess[r][c+1]&&
                          chess[r][c]==chess[r][c+2]&&
                          chess[r][c]==chess[r][c+3]&&
                          chess[r][c]==1)
                             JOptionPane.showMessageDialog(null,player1Name+" is a winner.");
                             hasAWinner=true;
                             return hasAWinner;
                     else if(chess[r][c]==chess[r][c+1]&&
                                chess[r][c]==chess[r][c+2]&&
                                chess[r][c]==chess[r][c+3]&&
                                chess[r][c]==2)
                             JOptionPane.showMessageDialog(null,player2Name+ " is a winner.");
                             hasAWinner=true;
                             return hasAWinner;
    //win at column
    for (int r=0;(r+3)<6;r++)
            for(int c=0;c<7;c++)
                    if(chess[r][c]==chess[r+1][c]&&
                           chess[r][c]==chess[r+2][c]&&
                           chess[r][c]==chess[r+3][c]&&
                           chess[r][c]==1)
                             JOptionPane.showMessageDialog(null, player1Name+" is a winner.");
                             hasAWinner=true;
                             return hasAWinner;
                      else if(chess[r][c]==chess[r+1][c]&&
                                 chess[r][c]==chess[r+2][c]&&
                                 chess[r][c]==chess[r+3][c]&&
                                 chess[r][c]==2)
                             JOptionPane.showMessageDialog(null,player2Name+" is a winner.");
                            hasAWinner=true;
                             return hasAWinner;
    //win at upleft-to-downright direction
    for (int r=0;(r+3)<6;r++)
            for(int c=0;(c+3)<7;c++)
                    if(chess[r][c]==chess[r+1][c+1]&&
                           chess[r][c]==chess[r+2][c+2]&&
                           chess[r][c]==chess[r+3][c+3]&&
                           chess[r][c]==1)
                             JOptionPane.showMessageDialog(null, player1Name+" is a winner.");
                             hasAWinner=true;
                             return hasAWinner;
                      else if(chess[r][c]==chess[r+1][c+1]&&
                                 chess[r][c]==chess[r+2][c+2]&&
                                 chess[r][c]==chess[r+3][c+3]&&
                                 chess[r][c]==2)
                             JOptionPane.showMessageDialog(null,player2Name+" is a winner.");
                            hasAWinner=true;
                             return hasAWinner;
    //win at downleft-to-upright direction
    for (int r=5;(r-3)>=0;r--)
            for(int c=0;(c+3)<7;c++)
                    if(chess[r][c]==chess[r-1][c+1]&&
                           chess[r][c]==chess[r-2][c+2]&&
                           chess[r][c]==chess[r-3][c+3]&&
                           chess[r][c]==1)
                             JOptionPane.showMessageDialog(null, player1Name+" is a winner.");
                             hasAWinner=true;
                             return hasAWinner;
                      else if(chess[r][c]==chess[r-1][c+1]&&
                                 chess[r][c]==chess[r-2][c+2]&&
                                 chess[r][c]==chess[r-3][c+3]&&
                                 chess[r][c]==2)
                             JOptionPane.showMessageDialog(null,player2Name+" is a winner.");
                            hasAWinner=true;
                             return hasAWinner;
    return hasAWinner;
    }//end hasAwinner
    public boolean hasATie()
         boolean hasATie=false;
         if(steps==42 && hasAWinner()==false)
                     JOptionPane.showMessageDialog(null,"The game has a a tie.");
                    hasATie=true;
                     return hasATie;
            return hasATie;
    }//end hasATie
    /***********************listener class *******************************************/
    private class myStartButton implements ActionListener
         public void actionPerformed(ActionEvent e)
              //JOptionPane.showMessageDialog(null,"Now the game starts.");
              input=JOptionPane.showInputDialog(player1Name+" enter your name and make a move.");//start the game
    private class myrePlayButton implements ActionListener
         public void actionPerformed(ActionEvent e)
            if(steps>0)
                        ///how to clear the old frame???
                    JOptionPane.showMessageDialog(null,"new game starts.");
                       input=JOptionPane.showInputDialog(player1Name+" enter your name and make a move.");//start the game
                 else
                      JOptionPane.showMessageDialog(null,"You haven't started a new game yet.");
    }//end myrePlayButton
    private class myexitButton implements ActionListener
         public void actionPerformed(ActionEvent e)
                                                          ///how to cancel????????
                          JOptionPane.showMessageDialog(null,"Are you sure you want to stop the game?");
                          if(e.getActionCommand().equals("Exit"))
                              {System.exit(0);}
    }//end myexitButton
    private class mybuttonsBoard implements ActionListener
         public void actionPerformed(ActionEvent e)
           for (int r=0; r<6; r++)
                     for (int c=0; c<7;c++)
                        if(e.getSource()==buttonsBoard[r][c]
                            &&chess[r][c]==0
                            &&input.equals(player1Name))
                             buttonsBoard[r][c].setBackground(Color.red);
                                       chess[r][c]=player1_ID;
                                            steps++;
                                if(hasAWinner()==true||hasATie()==true)//has a winner or tie
                                             gameOver=true;
                                             repaint();
                                            break;
                               else
                                      input=JOptionPane.showInputDialog(player2Name+
                                          " enter your name and make a move.");
                      else if(e.getSource()==buttonsBoard[r][c]
                               &&chess[r][c]==0
                               &&input.equals(player2Name))
                                    buttonsBoard[r][c].setBackground(Color.black);
                                         chess[r][c]=player2_ID;
                                              steps++;
                                         if(hasAWinner()==true||hasATie()==true)//has a winner or tie
                                                 gameOver=true;
                                                      break;
                                       else
                                            input=JOptionPane.showInputDialog(player1Name+
                                                            " enter your name and make a move.");
              }//end for
        if(gameOver==true)
                      JOptionPane.showMessageDialog(null,"press Replay to"+
                                         " replay the game or press Exit to exit the game");//replay the game
    }//end actionPerformed
    }//end class
    public static void main(String []args)
              Connect4GUI b=new Connect4GUI();
         }//end main
    }//end Board

    The problem is solved.

  • How to stop as files from running until a certain frame

    Hi all,
    I have a simple flash game with two frames at the moment.
    Most of the stuff that happens is in as files linked to
    different movie clips.
    I orignially only had one frame my background frame and when
    testing I just press ctl+enter and bamm away it goes the
    actionscript runs as soon as the movie/game starts and ergo the
    game plays.
    My problem is this, I now want to have a start/home frame at
    the beginning (of course) which has the start game button on which
    when clicked THEN starts the game.
    Currently the game starts in the first frame along with the
    start button :(
    How do I stop the game running straight away and my first
    frame only contains the start button, which when clicked then goes
    to the 2nd frame and starts the game?
    Reagrds,
    Red.

    A friend resolved the issue for me;
    By renaming the main contrustor and calling this in the start
    button Example action script applied to the button:
    START OF ACTION SCRIPT
    import flash.events.MouseEvent;
    stop();
    startBTN.addEventListener(MouseEvent.CLICK, startClick);
    function startClick(event:MouseEvent):void
    trace ("Button clicked");
    gotoAndStop(2);
    gameGo();
    /*gameGo() is the renamed main document class, renaming it
    prevents it from been run instanly
    and it is called from the button*/
    END OF ACTION SCRIPT

  • Is it possible to split audio separate while playing a game and chat

    While listening music and in the meantime play a game or have a chat session, I  find it disturbing that the audio from the game or chat session runs at the same time as the audio from the music. Ik makes me nervous. Is it possible to use 2 different audio, or stop the audio from the game and keep listening to the music.
    Or stop the game audio during the chat session?
    Somebody can tell me if it is possible?

    It is all right to charge your MBA any time you are using it, hot or not. See these authoritative article regarding Apple batteries for additional guidance:
    https://www.apple.com/support/macbookpro/batteries_power/
    Ciao.

  • Game Heap Space - Out Of Memory Error

    Hi there,
    Ive completed my pacman/space invaders hybrid game- which has a main game and two playable videos. Its all fine, but when I go to run it it says;
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 2" java.lang.OutOfMemoryError: Java heap space
    Ive come to realise that this error is from the amount of data used to make up the game/video with there being around 150 images for the videos. Ive temporarily corrected this problem by making each video 26 images long (2.6secs each) but to get the full experience the user need to see around 75images.
    After a bit of research I found that i needed to increase my 'heap space'- and I attempted to do this thru cmd, attemptin to increase it to 512mb.
    The problem is the game doesnt have a main, or at least not one that I nor the computer can locate. And to get the heap space to increase it needs a main?!
    I honestly dont know what I am doing here- but could anyone tell me how I can increase my heap space or locate a main? Im really confused!
    Any help appreciated
    Senor-Cojones

    Thanks for your help ArikArikArik, the problem with that method is.... 1. im not too sure how to use it :P and 2. In my original code the images are added to the tracker which waits from all the images to be loaded before it continues.
    import javax.swing.*;
    import java.applet.AudioClip;
    import java.awt.*;
    public class ICGGSApplet extends JApplet implements Runnable {
        // constants describing possible game states
        private static final int SHOW_MOVIE = 1;
        private static final int PLAY_GAME = 2;
        private static final int STOPPED = 3;
        private static final int SHOW_MOVIE2 = 4;
        private int gameState;   // the current game state
        private String name;     // the player's name
        private long frameStartTime;  // the time the last frame was displayed
        private Thread gameLoop;   // thread to run the game and movie
        // associated objects
        private Movie theMovie;      // Panel to display the movie
        private MonsterGame theGame;  // Panel to display the game
        private ICGGSPanel currentPanel;  // the currently displayed Panel (can be null)
        private Movie2 theMovie2; // Panel to display the second movie
         * Called when applet is first loaded
         *  sets up the attributes, load media, creates game objects
         *  and sets up interface
        public void init() {
            // neither the movie nor the game is currently playing
            currentPanel = null;
            gameState = STOPPED;
            name = "";
            // load up the audio files
            AudioClip theAudio = getAudioClip(getDocumentBase(), "../media/shock.wav");
            AudioClip theAudio2 = getAudioClip(getDocumentBase(), "../media/applause.wav");
            AudioClip theAudio3 = getAudioClip(getDocumentBase(), "../media/bomb.wav");
            AudioClip theAudio4 = getAudioClip(getDocumentBase(), "../media/cashtill.wav");
            AudioClip theAudio5 = getAudioClip(getDocumentBase(), "../media/pacman.wav");
            // create a media tracker to monitor the loading of the images
            MediaTracker theTracker = new MediaTracker(this);
            // load up the images for the movie
            Image movieImages[] = new Image[25];
            for (int i=0; i<movieImages.length; i++) {
                movieImages[i] = getImage(getDocumentBase(), "../media/movie" + (i+1) + ".jpg");
                theTracker.addImage(movieImages, i);
    // load up the images for the second movie
    Image movieImages2[] = new Image[25];
    for (int i=0; i<movieImages2.length; i++) {
    movieImages2[i] = getImage(getDocumentBase(), "../media/firingGun" + (i+1) + ".jpg");
    theTracker.addImage(movieImages2[i], i);
    // load up the images for the munchies
    Image image1 = getImage(getDocumentBase(), "../media/munchie1.gif");
    theTracker.addImage(image1, 4);
    Image image2 = getImage(getDocumentBase(), "../media/munchie2.gif");
    theTracker.addImage(image2, 5);
    Image image3 = getImage(getDocumentBase(), "../media/munchie3.gif");
    theTracker.addImage(image3, 6);
    // wait for all the images to be loaded
    try {
    theTracker.waitForAll();
    } catch (InterruptedException e) {
    // create the movie object
    theMovie = new Movie(movieImages);
    theMovie2 = new Movie2(movieImages2);
    // create the game object
    theGame = new MonsterGame(image1, image2, image3, theAudio, theAudio2, theAudio3, theAudio4, theAudio5);
    this.getContentPane().setBackground(Color.WHITE);
    // Initialise key-input functionality
    addKeyListener(new Input()); // add keyboard listener to applet
    * Called when the Applet is ready to start executing
    public void start() {
    // ask the user for their name
    name = JOptionPane.showInputDialog(this, "What is your name?");
    // start running the movie/game animation
    if (gameLoop == null) {
    gameLoop = new Thread(this);
    gameLoop.start();
    * Called when the gameLoop thread is started
    * loops continuously until user quits
    public void run() {
    int input = Input.NONE;
    // game loop
    while (input != Input.QUIT) {
    // what is the current time?
    frameStartTime = System.currentTimeMillis();
    input = checkInput();
    if (gameState != STOPPED) // only necessary if the movie or game is showing
    currentPanel.processInput(input);
    currentPanel.update();
    currentPanel.repaint();
    } else
    showStatus("Press 'G' to start game, 'M' to show movie or 'F' to show the second movie");
    frameDelay(100);
    * called when the Applet is stopped
    * stops the gameLoop thread
    public void stop() {
    if (gameLoop != null) {
    gameLoop.interrupt(); // stops the animation thread
    gameLoop = null;
    * called from the gameLoop
    * checks for the last key stroke input by the user
    * @return int - Input class constant representing user input
    public int checkInput() {
    int input = Input.checkUserInput();
    switch (input) // how the input is handled depends on the current game state
    case Input.GAME:
    // the user wants to play the game
    if (gameState == STOPPED) // not currently playing a game or movie
    // display the panel showing the game
    currentPanel = theGame;
    this.getContentPane().add(BorderLayout.CENTER, currentPanel);
    this.validate();
    // set up a new game
    theGame.resetGame();
    gameState = PLAY_GAME;
    showStatus("Use arrow keys to move Monster, S key to stop");
    } // otherwise ignore
    break;
    case Input.MOVIE:
    // the user wants to see the movie
    if (gameState == STOPPED) // not currently playing a game or movie
    // display the panel showing the movie
    currentPanel = theMovie;
    this.getContentPane().add(BorderLayout.CENTER, currentPanel);
    this.validate();
    gameState = SHOW_MOVIE;
    showStatus("Press S key to stop");
    } // otherwise ignore
    break;
    case Input.MOVIE2:
    // the user wants to see the second movie
    if (gameState == STOPPED) // not currently playing a game or movie
    // display the panel showing the movie
    currentPanel = theMovie2;
    this.getContentPane().add(BorderLayout.CENTER, currentPanel);
    this.validate();
    gameState = SHOW_MOVIE2;
    showStatus("Press S key to stop");
    } // otherwise ignore
    break;
    case Input.STOP:
    // the user wants to stop the movie or game being shown
    if (gameState == SHOW_MOVIE ) {
    this.getContentPane().remove(currentPanel);
    currentPanel = null;
    JOptionPane.showMessageDialog(this,
    "OK " + name + " I've stopped the movie");
    } else if (gameState == PLAY_GAME) {
    this.getContentPane().remove(currentPanel);
    currentPanel = null;
    JOptionPane.showMessageDialog(this,
    "OK " + name + " I've stopped the game");
    } else if (gameState == SHOW_MOVIE2 ) {
    this.getContentPane().remove(currentPanel);
    currentPanel = null;
    JOptionPane.showMessageDialog(this,
    "OK " + name + " I've stopped the movie"); }
    gameState = STOPPED;
    showStatus("Press 'G' to start game, 'M' to show movie");
    break;
    Input.reset(); // reset the input module
    requestFocus();
    this.repaint(); // redisplay the applet
    return input; // return for further processing (eg to control movement of Monster)
    * called from the gameLoop
    * pauses between frames
    * @param millis long - minimum frame time
    public void frameDelay(long millis) {
    long currentTime = System.currentTimeMillis(); // what time is it now?
    long elapsedTime = frameStartTime - currentTime; // how long has it been since the start of the frame?
    if (elapsedTime < millis) // is it time to showing the new frame yet?
    try {
    Thread.sleep(millis - elapsedTime); // pause for the remaining time
    } catch(Exception e) {
    Thats the whole code for the applet- preloadin the image (and also everything that doesnt relate to this problem lol). Ive asked around and the answer I was given I wasnt satisfied with- make the files smaller/delete some- the files are already at their smallest about 10kb each. And also apparently (I didnt know this...) but due to security restirictions I wouldnt be able to increase the heap size anyway (this is to run the applet on my own... and others computers).
    So Im really too sure what to do at the minute. Anymore help would be appreciated though.
    Thank you!
    Senor-Cojones

Maybe you are looking for

  • DATA AGGREGATION ISSUE IN REPORT

    Hi, when we were running query by selcting the the version  . the data is aggregation dono where it went rong Explanation : we  alredy loaded data with version for the year 2010.. we started laoding from April 2010 to March 2011.. as 12 fiscal period

  • ESYU: R12 - Order 입력 화면(OEXOEORD)의 모든 fields가 grayed out 인 경우

    Purpose Oracle Order Management - Version: 12.0 to 12.0 This problem can occur on any platform. OEXOEORD.fmb OEXOEBSO.fmb R12 version의 Sales Order form이나 Sales Agreement form(OEXOEORD or OEXOEBSO)의 모든 fields가 greyed out인 경우 해결 방법에 대해 알아본다. Solution 이

  • GetDescriptions() of an object loaded from local variable 'itemDeploymentResult'

    Hi We are urgrading our SAP MII ( purely Java ) systems from 7.31 Sp5 to 7.40 and we got stuck at Configuration phase. We are getting the following error during Queue validation. Checking of deployment queue completed with error. java.lang.NullPointe

  • Frames Dropping when Editing back to tape

    I just updated my Final Cut Studio to 5.1.4. I am running this program on 2.0 GHz G5 Power Mac. I have fibre from the G5 to the server. I am trying to Edit to tape and this edit stop because it had dropped one or more frames. I am at OS 10.4.9 The er

  • Solaris 10 on Dell hardware - To RAID or not....

    Hi Guys, Looking for a bit of help. In my current role I administer solaris 7-10 on sparc but am soon to be involved in some installs of 10 in a PowerEdge 850. My concern is mirroring. I'm quite capable of using ODS/SDS to do this at the software lev