0

I am making a project, which contains one splash/loading screen in the beginning (it works properly) and one in the end of the program. The exiting splash screen doesn't appear and when the set time is up its appear with the text "Loading...100%".

try {
    LoadingPage2 lg2 = new LoadingPage2();
    lg2.setVisible(true);
    for (int i = 0; i <= 100; i++) {
        Thread.sleep(40);
        lg2.lblPercentage.setText(lg2.loading + Integer.toString(i) + "%");
    }
    System.exit(0);
} catch (InterruptedException e1) {
    e1.printStackTrace();
}
Chris
  • 26,361
  • 5
  • 21
  • 42
  • 1
    Swing is single threaded and not thread safe. This means you can't execute long running or blocking operations from within the context of the Event Dispatching Thread and you shouldn't update the state of the UI or something the UI relies on from outside of the Event Dispatching Thread – MadProgrammer May 23 '22 at 21:25
  • See [Concurrency in Swing](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html) for more details. If you need to (long running or blocking) do work AND want to update the UI, then I recommend using a [`SwingWorker`](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) – MadProgrammer May 23 '22 at 21:26
  • For [example](https://stackoverflow.com/questions/24835638/issues-with-swingworker-and-jprogressbar/24835935#24835935), [example](https://stackoverflow.com/questions/67494618/java-gui-progress-bar-doesnt-update-until-the-async-task-is-finished/67500628#67500628); [example](https://stackoverflow.com/questions/16633414/gui-display-lines-one-by-one-on-a-jtextpane-and-make-a-related-jprogressbar/16633506#16633506); [example](https://stackoverflow.com/questions/23125642/swingworker-in-another-swingworkers-done-method/23126410#23126410) – MadProgrammer May 23 '22 at 21:30
  • Plz us ful wrdz wen pstn her. – Basil Bourque May 23 '22 at 21:59

0 Answers0