0

I have class that updates a component that is synchronized to a song. When I first run it, it takes a while to load the song, then displays the graphics piece by piece as they load.

I was wondering if/how to have the JFrame display a loading screen while it is loading both my Clip and my component's graphics.

Also, "stageComponent.setDoubleBuffered(true)" doesnt seem to do anything.

public static void main(String[] args)
{
    loadSong(SONG_NAME);

    JFrame frame = new JFrame(TITLE);

    stageComponent = new StageComponent();
    stageComponent.setDoubleBuffered(true);
    frame.add(stageComponent);

    frame.setVisible(true);

    // If my stuff is loaded then start it all?
    if (stageComponent.isShowing() && clip.isOpen()) {
        Timer t = new Timer(TIME_DELAY, null);

        final long initialTime = System.currentTimeMillis();

        ActionListener stageListener = new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                stageComponent.playSequences((int)(System.currentTimeMillis() - initialTime));
            }
        };
        t.addActionListener(stageListener);

        // This will play song and start timer at basically the same time right?
        clip.start();
        t.start();
    }
}

Thanks in advance!

Connor
  • 670
  • 3
  • 9
  • 29
  • 1
    The basic premise would be to have a third window. You would load the music in a background process and display a nice splash/message screen. When it's done, you would display the main screen. Just remember, you are expected to interact with the UI from within the context of the event dispatching thread – MadProgrammer Nov 08 '13 at 00:28
  • Okay well how do I know when the music is done loading? "clip.isOpen() or clip.isActive()"? And what about the graphics loading. "setDoubleBuffered" doesn't seem to do the trick... – Connor Nov 08 '13 at 02:10
  • There is no real way to know when the UI will be fully realised on the screen. The best you can hope for is knowing when you've loaded any resources (such as images). `setDoubleBuffered` will only make a difference to the quality of the updates to the component – MadProgrammer Nov 08 '13 at 02:28

0 Answers0