0
import java.awt.*;

public class GUiJava{
  GUiJava(){
    Frame fm = new Frame();
    Label lb = new Label("Welcome to the First GUI");
    fm.add(lb);
    fm.setSize(300,300);
    fm.setVisible(true);
  }

  public static void main(String[] args){
    GUiJava gu = new GUiJava();
  }
}

I am trying to learn Java GUI, but When I try to run the program, I get an error like the one below.

When I use Swing or AWT, I get the same error. I have tried out some possible solutions of setting the Display variable, they don't work.

Exception in thread "main" java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208)
        at java.desktop/java.awt.Window.<init>(Window.java:548)
        at java.desktop/java.awt.Frame.<init>(Frame.java:423)
        at java.desktop/java.awt.Frame.<init>(Frame.java:388)
        at GUiJava.<init>(GUiJava.java:6)
        at GUiJava.main(GUiJava.java:14)
Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
enockmale
  • 1
  • 4
  • *"When I use swing, or awt, I get the same error"* **Don't** use AWT! See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. – Andrew Thompson Aug 12 '21 at 04:24

0 Answers0