I created my java program with NetBeans and it works fine. However, when I try to run it with the terminal it can print to std out but it won't display my JFrame window (the terminal just hangs). Here my sample code:
package hello;
import javax.swing.*;
public class Main {
private static void window() {
JFrame frame = new JFrame("Hello World");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello World!");
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Here is my JFrame");
window()
}
}
What I did was:
javac hello/*.java
java hello/Main
Does anyone know what's wrong?
package hello;
import javax.swing.*;
public class Main {
private static void window() {
JFrame frame = new JFrame("Hello World");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello World!");
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Here is my JFrame");
window()
}
}
What I did was:
javac hello/*.java
java hello/Main
Does anyone know what's wrong?