Switching Screens Speed?

Hello everyone again,
I'm pretty new to programming in Java and I'm getting an error in my program. The program runs fine but it's slower than I wanted. The Windows Consol does not give any errors. The program displays a title screen of a game I'm making with background music and a button. When the button is pressed, it changes screen to a 2nd screen which also has a button. The 2nd screen playes a different music and also has a button which exits when pressed. Pushing the Esc key exits out of the game, which is full screen. However, there seems to be a delay of 5 to 20 seconds every time I push the button to switch screens and whenever I start the program. Why is it doing this?
I have some ideas, but I'm not sure if they are right. I'm guessing that it really slows down because I need to buffer the images. If it's not the image that slows down the program, is it the SoundManager? Maybe it's something I'm not seeing, so please take a look and give out any suggestions.
Thanks
Here's the code...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.sound.sampled.AudioFormat;
import com.brackeen.javagamebook.sound.*;
import com.brackeen.javagamebook.input.*;
import com.brackeen.javagamebook.graphics.*;
import com.brackeen.javagamebook.test.*;
class YGOGrandChampionship extends JFrame implements ActionListener
    private JButton startButton;
    private static ImagePanel ip = new ImagePanel("Title Screen.jpg", "Title.gif");
    private Image Title = loadImage("Title.gif");
    protected GameAction exit;
    protected InputManager inputManager;
    AudioFormat PLAYBACK_FORMAT = new AudioFormat(44100, 16, 2, true, false);
        SoundManager soundManagerS = new SoundManager(PLAYBACK_FORMAT);
     public YGOGrandChampionship()
          //Makes it Full Screen.
          setUndecorated(true);
          BorderLayout x = new BorderLayout(0, 500);
          ip.setLayout(x);
          JPanel buttonPanel = new JPanel();
          GridBagConstraints grid = new GridBagConstraints();
          //Creates the Start Button.
          startButton = createButton("Start.gif");
          grid.gridwidth = GridBagConstraints.SOUTH;
          //Sets the Location of the Title.
          ip.setLocation (342, 244);
          buttonPanel.setOpaque(false);
          startButton.setBounds(460, 500, 104, 43);
          buttonPanel.add(startButton);
          buttonPanel.setLayout(null);
          ip.add(buttonPanel);
          //Adds it to the Content Pane.
          getContentPane().add(ip);
          //Makes it pop up.
          setExtendedState(MAXIMIZED_BOTH);
          addKeyListener(new KeyListener()
               public void keyPressed(KeyEvent event)
                    //Does nothing until released.
               public void keyReleased(KeyEvent event)
                    if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
                         //Exits the program.
                         System.exit(0);
               public void keyTyped(KeyEvent event) {}
          startButton.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                  // fire the "next screen" gameAction
                    soundManagerS.close();
                    new MenuScreen().setVisible(true);
                    SoundManager soundManager = new SoundManager(PLAYBACK_FORMAT);
                    Sound nextMusic = soundManager.getSound("movie36.wav");
                    soundManager.play(nextMusic);
     public Image loadImage(String fileName)
        return new ImageIcon(fileName).getImage();
     public JButton createButton(String name)
         String imagePath = name;
         ImageIcon iconRollover = new ImageIcon(imagePath);
         Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
         // create the button
         JButton button = new JButton();
         button.addActionListener(this);
         button.setIgnoreRepaint(true);
         button.setFocusable(false);
         button.setBorder(null);
         button.setContentAreaFilled(false);
         button.setCursor(cursor);
         button.setIcon(iconRollover);
         button.setRolloverIcon(iconRollover);
         button.setPressedIcon(iconRollover);
         return button;
       public void actionPerformed(ActionEvent e)
        Object src = e.getSource();
    public static void main(String[] args)
          AudioFormat PLAYBACK_FORMAT =
         new AudioFormat(44100, 16, 2, true, false);
         SoundManager soundManager = new SoundManager(PLAYBACK_FORMAT);
         Sound titleMusic = soundManager.getSound("movie02.wav");
          soundManager.play(titleMusic);
          new YGOGrandChampionship().setVisible(true);
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.sound.sampled.AudioFormat;
import com.brackeen.javagamebook.sound.*;
import com.brackeen.javagamebook.input.*;
import com.brackeen.javagamebook.graphics.*;
import com.brackeen.javagamebook.test.*;
class MenuScreen extends JFrame implements ActionListener
    private JButton newGameButton;
    private static ImagePanel ip = new ImagePanel("kaiba_seto.jpg", "Title.gif");
    private Image Title = loadImage("Title.gif");
    protected GameAction exit;
    protected InputManager inputManager;
    AudioFormat PLAYBACK_FORMAT = new AudioFormat(44100, 16, 2, true, false);
        SoundManager soundManagerM = new SoundManager(PLAYBACK_FORMAT);
     public MenuScreen()
          //Makes it Full Screen.
          setUndecorated(true);
          BorderLayout x = new BorderLayout(0, 500);
          ip.setLayout(x);
          JPanel buttonPanel = new JPanel();
          GridBagConstraints grid = new GridBagConstraints();
          //Creates the Start Button.
          newGameButton = createButton("New Game.jpg");
          grid.gridwidth = GridBagConstraints.SOUTH;
          //Sets the Location of the Title.
          ip.setLocation (0, 500);
          buttonPanel.setOpaque(false);
          newGameButton.setBounds(300, 600, 256, 67);
          buttonPanel.add(newGameButton);
          buttonPanel.setLayout(null);
          ip.add(buttonPanel);
          //Adds it to the Content Pane.
          getContentPane().add(ip);
          //Makes it pop up.
          setExtendedState(MAXIMIZED_BOTH);
          addKeyListener(new KeyListener()
               public void keyPressed(KeyEvent event)
                    //Does nothing until released.
               public void keyReleased(KeyEvent event)
                    if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
                         //Exits the program.
                         System.exit(0);
               public void keyTyped(KeyEvent event) {}
          newGameButton.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                  // fire the "exit" gameAction
                  System.exit(0);
     public Image loadImage(String fileName)
        return new ImageIcon(fileName).getImage();
     public JButton createButton(String name)
         String imagePath = name;
         ImageIcon iconRollover = new ImageIcon(imagePath);
         Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
         // create the button
         JButton button = new JButton();
         button.addActionListener(this);
         button.setIgnoreRepaint(true);
         button.setFocusable(false);
         button.setBorder(null);
         button.setContentAreaFilled(false);
         button.setCursor(cursor);
         button.setIcon(iconRollover);
         button.setRolloverIcon(iconRollover);
         button.setPressedIcon(iconRollover);
         return button;
       public void actionPerformed(ActionEvent e)
        Object src = e.getSource();
import javax.swing.*;
import java.awt.*;
class ImagePanel extends JPanel
     Image img, sImg;
     int x = 0, y = 0;
     public ImagePanel (String fileName, String fileName2)
          try
               img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(fileName), fileName));
               sImg = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(fileName2), fileName2));
          catch(Exception e){/*handled in paintComponent()*/}
     public void setLocation (int x1, int y1)
          x = x1;
          y = y1;
     public void switchBackground (String fileName)
          try
               img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(fileName), fileName));
          catch(Exception e){/*handled in paintComponent()*/}
     public void paintComponent(Graphics g)
          super.paintComponent(g);
          if(img != null) g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this);
          else g.drawString("No image file found", 50, 50);
          if(sImg != null) g.drawImage(sImg, x, y ,this);
          else g.drawString("No image file found", 100, 100);
}

I do agree... it could be the sound manager, cause if i am not wrong once the song/sound is loaded.. it is not garbarge collected when the new sound is loaded. Maybe you might want to ensure to get rid of the previous sound before loading the next one???

Similar Messages

  • Unable to switch  screen mode from standard: PS CS5

    Full screen with or without menus is grayed out in the view menu and the view dropdown selector from the menu bar. I have quit and re-entered PS and have reset all workspaces to default. I have checked that I'm working in 64 bit. I still cannot switch screen mode from standard. Last update was to 12.04. Last extension installed was photokit sharpener.
    Thanks for any help. (PS, how do I reset preferences file on a mac?)
    Cathy
    Pertinent info:
    Adobe Photoshop Version: 12.0.4 (12.0.4x20110407 [20110407.r.1265 2011/04/07:02:00:00 cutoff; r branch]) x64
    Operating System: Mac OS 10.6.7
    System architecture: Intel CPU Family:6, Model:37, Stepping:5 with MMX, SSE Integer, SSE FP, SSE2, SSE3, SSE4.1, SSE4.2, HyperThreading
    Physical processor count: 2
    Logical processor count: 4
    Processor speed: 3200 MHz
    Built-in memory: 4096 MB
    Free memory: 2353 MB
    Memory available to Photoshop: 3698 MB
    Memory used by Photoshop: 69 %
    Image tile size: 128K
    Image cache levels: 4
    OpenGL Drawing: Enabled.
    OpenGL Drawing Mode: Normal
    OpenGL Allow Normal Mode: True.
    OpenGL Allow Advanced Mode: False.
    OpenGL Crash File: Not Detected.
    OpenGL Allow Old GPUs: Not Detected.
    OpenGL Version: 2.1 ATI-1.6.26
    Video Card Vendor: ATI Technologies Inc.
    Video Card Renderer: ATI Radeon HD 5670 OpenGL Engine
    Display: 1
    Main Display
    Display Depth:= 32
    Display Bounds:=  top: 0, left: 0, bottom: 1080, right: 1920
    Video Renderer ID: 16915203
    Video Card Memory: 501 MB

    Ahh, I knew it was probably something simple. No I didn't have a doc open since I was just working with prefs and trying to set desktop color. Banging my head now on my desk. Bam! So dumb ...
    Thanks so much for solving my problem.

  • Switch screen button in keynote 6.0

    I had my first presentation today with Keynote 6.0. Everything was fine except at the conclusion I wanted to find out how to get to the other slides. I was checking the buttons at the top right and pushed what I now realize is "switch screen." Now what I should see on my computer (presenter view with slides) is what they see on the screen. I've looked everwhere and I can't find a 'switch screen'so that I can reverse it and when I'm in presenter mode, there's no way to find that. Any help would be much appreciated!

    Thank you so much. I didn't know that shortcut and it fixed it right away. I was surprised that when I went back to the section that all of those slide were only a small portion of the page. It's almost like the white part of the slide got bigger so the actual slide information shrunk. Obviously I hit something in my frustration that changed the slide size, but luckily it will be easy to replace. Great response to my question and much appreciated!

  • Doing keynote presentation.  How do I switch screens so the audience does not see my notes and next slide?

    Doing keynote presentation.  How do I switch screens so the audience does not see my notes and next slide?

    Go to Keynote>Help>Show your Presentation>Use Presenter notes.
    Also if you are using separate screens see Present on seperate displays

  • My 3 GS has been working fine for the last two years or so but recently it has been getting "stuck" frequently when I try to do various things - answer a phone call, switch screens, go to my mail, etc.

    My 3 GS has been working fine for the last two years or so but recently it has been getting "stuck" frequently when I try to do various things - answer a phone call, switch screens, go to my mail, etc.

    Hello binbingogoABC,
    Shopping on BestBuy.com should be easy and fun and not fraught with the kind of trouble that you describe. I regret very much that this has been your experience.
    Using the information you provided when you signed up for Best Buy Unboxed I was able to locate your cancelled orders. I have requested more information from my back-office partners. As soon as I have additional details about your situation, I will reply again to this message. In the interim, I'm sorry that I must impose upon your patience.
    I'm very grateful that you wrote to us with your concerns.
    Sincerely,

  • Can't move pointer after switch screen.

    Hi, I am using a hp compaq laptop, after switching screen (ctrl+alt f1), then (ctrl+alt f7), the mouse won't move. Can anyone help me please. Thx
    /etc/X11/xorg.conf
    Section "InputDevice"
    # generated from default
    Identifier "Mouse0"
    Driver "mouse"
    Option "Protocol" "auto"
    Option "Device" "/dev/psaux"
    Option "Emulate3Buttons" "no"
    Option "ZAxisMapping" "4 5"
    EndSection

    Everything works fine exept for the mouse. Even after a fresh install, problem still remains. I tried starting x with and without gdm, still have problems. dmesg didn't saying anything wrong with mouse.

  • IPad 2 side buttons no longer work after switching screen

    My screen got cracked 4 months ago, but I still used it perfectly fine. Last week i paid a guy to replace my screen, after which, the side buttons (top switch, screen lock/mute, and volume buttons) stopped workiing. The home button is the only button that works. What is causing this and are there any apps i can download that can lock my screen with (so i can tilt is sideways without the screen shifting)? BTW, the guy who did the job said it's not his fault so i cant do anything on that end.

    aThen a button will appear on your screen click that then it will give you a device option click on that and you can lock your screen turn the volume up and down and lock the screen rotation. Hope this helps!

  • My Ipad (purchased 5/12) constantly switches screens without prompting.  This happens about every 3 seconds.

    I purchased my iPad 5/12.  Since a recent trip inwhich I used a verizon hotspot device to stay connected, it switches screens without prompting.  New screens pop up about every 3-5 seconds.  How can I reset?

    Hold the Sleep and Home button down (together) for about 10 seconds until you see the Apple logo. Ignore the red slider.

  • I cannot switch screens on my Apple TV

    I marrying to switch screens between using the iPad on Apple TV and the remote showing the icons

    Same here! Just a few days ago it started. Nothing will play from the cloud. Browsing the store works, streaming from a computer works, airplay works. Just none of my tv or movie purchases in the cloud.
    I've reset it a few times. Ran the network test and it's passed every time. I've tried setting static ip and DNS info to no avail. I'm clueless. It almost feels like my ISP is blocking it but that's crazy talk.
    Anything else to try? Tomorrow I'm going to hook it up to Ethernet and see what happens. As of now though, this is a mystery.

  • Switch screens with keyboard

    it's annoying to switch screens because i have to take control of the mouse to do it when hes usually doin something, so is there any way to switch back to my screen with the keyboard?

    Do you mean "screens" as in Spaces or "windows" as in Finder or an application? For OS X shortcuts see Mac OS X keyboard shortcuts. For Spaces simply open its preference pane where you can see the currently assigned shortcut or assign your own.

  • Not smooth when switch screen on my RMBP

    I upgrade my Retian Macbook Pro to OS X Mountain Lion and I found when I switch screen it is not as smooth as it used to be when the computer is running with the Intel graphics 4000. It's kind of dazed for me when switching to wallpapaer. It became better if I choose to use the GT650M but it will use more power. Anyone have the same feeling?

    I upgrade my Retian Macbook Pro to OS X Mountain Lion and I found when I switch screen it is not as smooth as it used to be when the computer is running with the Intel graphics 4000. It's kind of dazed for me when switching to wallpapaer. It became better if I choose to use the GT650M but it will use more power. Anyone have the same feeling?

  • HT4061 My IPad is slow when I type something....other times takes too long to switch screen or apps

    I have problems with my iPad.  It is slow to switch screens and apps, also the switch bottom to change screens is terrible...sometimes doesn't response.

    Try closing all apps completely and then do a soft-reset and see if that helps. To close all apps : from the home screen (i.e. not with any app 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of each app to close them, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    To do a soft-reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Computer randomly switching screens

    I have had my computer for two months.  The last week I have had a problem with the computer switching screens without my clicking on a site.
    If I am deleting e-mail, it may delete two or three e-mails instead of one.  If the cursor happens to rest over a link, the screen will go there.
    I was on the Track Pad  in Preferences to see what the setting were before this happened so I may have inadvertantly changed something I shouldn't have.
    Thanks

    I would take it to the Apple Store. Make a Genius Bar appointment. They have equipment and such to do hardware tests and things like that.
    Genius Bar Reservations (they should not charge you anything unless they actually need to do work on it, if I am not mistaken).

  • Not smooth when switching screen to wallpaper in OS X ML

    I upgrade my Retian Macbook Pro to OS X Mountain Lion and I found when I switch screen it is not as smooth as it used to be when the computer is running with the Intel graphics 4000. It's kind of dazed for me when switching to wallpapaer. It became better if I choose to use the GT650M but it will use more power. Anyone have the same feeling?

    You can still do it with CONTROL + Arrow keys, the same as 10.6
    Regards,
    Captfred

  • My iphone will not switch screens when I push the button

    my iphone will not switch screens when I push the button

    -try restarting the device
    -reset the device
    -restore the device as new
    -replace the device

Maybe you are looking for

  • Converting .avi files for use in iDVD

    I have multiple .avi files that I'd like to add to a DVD using iDVD. These files are in their original format at 30 kb/sec and not compressed at all so they are HUGE...totaling almost 20G. What is the best way to convert these files so that they can

  • How can I sort Library by name?

    After migrating to iMovie 11 and having all my folders by year wiped out, I'm trying to figure out how to reorder my library so the events are in order by date. I don't think there is a way to make an iMove library sort by date (please tell me if wro

  • Aol mail 2 inches wide

    why is the aol mail page 2 inches wide I have no idea how long this has been going on, I'm on my fathers computer and I don't use aol. When I tried to bring up his mail the page came up two inches wide. Then when you click on another tab the aol mail

  • Tablespace check inconsistant in DB02

    Run DB02: Under the default folder Space, double click Tablespaces, check tablespace DOCUI, we can find that there is still 157,952 KB free space and the percent used is only 31.25%.  However under the folder Diagnostics, double click Single System C

  • Checking for latest version process

    I'm currently testing the Java Web Start technology with an applet. I'm dealing with a total of 2.8 meg of jar files divided up into approx 20 jars. It currently takes approximately 20 - 30 seconds for Java Web Start to determine if the cached jars a