I must point out that the application is actually not "halted" or "paused", it's only because the console output stream is blocked whenever you click on the command window, and if you see the whole application pausing, it's because these programs don't implement multithreading and non-blocking IO correctly.
You can easily verify this by writing a multi-threading application. For example, the following Java application shows a login dialog and continues to output text on the console. When the console blocks, you can still interact with the GUI.
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class SwingLoginExample {
public static void main(String[] args) {
new Thread(() -> {
var i = 0;
while (true) {
i++;
System.out.println("Hello World! " + i); // System.out.println is a blocking method in java
}
}).start();
JFrame frame = new JFrame("Login Example");
// Setting the width and height of frame
frame.setSize(350, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
placeComponents(panel);
frame.setVisible(true);
}
private static void placeComponents(JPanel panel) {
panel.setLayout(null);
JLabel userLabel = new JLabel("User:");
userLabel.setBounds(10,20,80,25);
panel.add(userLabel);
JTextField userText = new JTextField(20);
userText.setBounds(100,20,165,25);
panel.add(userText);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(10,50,80,25);
panel.add(passwordLabel);
JPasswordField passwordText = new JPasswordField(20);
passwordText.setBounds(100,50,165,25);
panel.add(passwordText);
JButton loginButton = new JButton("login");
loginButton.setBounds(10, 80, 80, 25);
panel.add(loginButton);
}
}
You should always avoid calling print() or similar methods directly; if the console responds slowly, your program will be slowed down as a result. Create a thread to perform the print() task, or use a non-blocking alternative.