I’m having some trouble with getting input from the command line before opening a GUI window. I asked this question previously on Apple Exchange but was sent here after we determined it to be a Programming problem. Basically I’m running a Scanner to get user input before I open up a window but it starts the program, switching spaces on my Mac, and then I have to switch back to the workspace with the terminal in it to answer the question. Here’s a link to the original question.
Here’s the code I’ve tested with…
public class Client extends JFrame {
public static void main(String[]args) {
Scanner in = new Scanner(System.in);
System.out.printf("\nGive me a size for the screen: ");
String response = in.nextLine();
new Client(response);
}
public Client(String title) {
super(title);
super.setVisible(true);
}
}
Use
invokeLater()to start the GUI after you get the input.Note that your example runs fine on my platform due to timing differences. Also consider using the
argsarray to pass parameters, or ask the implementation, as shown inFullScreenTestAddendum: Reading your other thread a little closer, you can use the following approach that launches a
NamedFramein a separate JVM.