Whenever I click the event button the program becomes unresponsive Is there something wrong with my code?
void btnConnectActionPerformed(java.awt.event.ActionEvent evt){
try{
btnSend.setEnabled(true);
ServerSocket serverSocket = new ServerSocket(4446);
Scanner serverType = new Scanner(chatTxt.getText());
Socket clientSocket = serverSocket.accept();
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader br = new BufferedReader(isr);
PrintStream ps = new PrintStream(clientSocket.getOutputStream());
}catch (Exception ex){ex.printStackTrace();}
}
No, nothing wrong with the code, except you executing a time consuming task within the
Event Dispatching Thread.This will prevent the UI from been updated as the
EDTis responsible for processing paint updates as well as handling keyboard and mouse event processing.As already suggested, check out Concurrency in Swing for more details.