Is it possible to shorten the startup time of my application?

1

I've seen a lot of things here and StackOverflow in English about Swing and Runnable , even though I could not solve my problem.

I am developing a work for college (interdisciplinary work, involving Distributed Systems / Advanced Data Structures / Technology and Education), which consists of a Crossword puzzle game. The problem is that the user will have the possibility to "mount" the Crossword.

That is, from a secondary window, it will inform you how many rows and columns the Crossword will have. The minimum quantity will be 10 rows per 10 columns. As you may have already guessed, when you close the form and call the method that builds the interface ( JTextField array) in the main window, there is an approximate time of 8 seconds until the window "thaws." And the time gets bigger as the "grid" grows too. As a parameter: For the construction of a grid of 15 X 15, the matrix appears in approximately 1 second. However, it takes 18 seconds to "defrost".

Is there a solution to this problem?

    
asked by anonymous 12.10.2015 / 04:01

1 answer

2

Use EDT.

The event dispatching thread (EDT) is a Java thread for handling Abstract Window Toolkit (AWT) events, it queues the events coming from the interface to handle in parallel. It is a classic example of the concept of event-oriented programming, which is popular in many other contexts, for example, web browsers or web servers.

It implements the worker design pattern to do this parallel processing of the interface and thus can handle multiple tasks.

public void actionPerformed(ActionEvent e)
{
  new Thread(new Runnable()
  {
    final String text = readHugeFile();
    SwingUtilities.invokeLater(new Runnable() 
    {
      public void run()
      {
        textArea.setText(text);
      }
    });
  }).start();
}

See the example, it uses the SwingUtilities class that invokes a new thread to set text . This type of approach might be the solution to your problem.

    
12.10.2015 / 18:46