Jarrel Costiniano
Jarrel Costiniano

Reputation: 7

JFrame freezing when I call a class using JButton

Im not really an expert in programming and Im just starting to learn. Here is my problem. I tried to call this class to start the server using a JButton but after the button was pressed the application freezes.

Here is my mouseClicked event

private void startbtnActionPerformed(java.awt.event.ActionEvent evt) {                                                
      new DisplayServer(80);
}  

Upvotes: 0

Views: 48

Answers (1)

Sergiy Medvynskyy
Sergiy Medvynskyy

Reputation: 11327

I suppose you block the Event Dispatcher Thread. Try to run it in a new Thread.

private void startbtnActionPerformed(java.awt.event.ActionEvent evt) {                          
  new Thread(new Runnable() {
      public void run() {
          new DisplayServer(80);
      }
  }).start();                      
}  

For more info read the article about Concurrency in Swing

Upvotes: 1

Related Questions