Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a graphical interface is supported?

Tags:

I need my Java program to have two display modes: a GUI interface and a command line interface. If I run it in Windows, OS X, or another graphical environment I should get the GUI interface, but if I run it via SSH I should get the command line interface.

How can I detect whether a GUI can be displayed or if I should use a command line interface?

like image 500
Filipe YaBa Polido Avatar asked Nov 22 '10 12:11

Filipe YaBa Polido


People also ask

What is the difference between a GUI and a CLI?

But there is a major difference between CLI and GUI. GUI lets a user interact with the device/system with the help of graphical elements, like windows, menus, icons, etc. The CLI, on the other hand, lets a user interact with their device/system with the help of various commands.

Is CLI better than GUI?

CLI is faster than GUI. The speed of GUI is slower than CLI. 5. CLI operating system needs only a keyboard.

How do I know if Java is headless?

Note: The isHeadless() method checks the specific system property, java. awt. headless , instead of the system's hardware configuration. A HeadlessException is thrown when code that depends on a display device, keyboard, or mouse is called in an environment that does not support any of these.


1 Answers

You actually have two questions:

1) Check if you run in a headless environment (no graphics). Check this method:

if (GraphicsEnvironment.isHeadless()) {      // non gui mode } else {      // gui mode } 

2) Check which OS you are running under:

System.getProperty("os.name") 

However, the second (2) question will return the same name even though you operate in a headless environment.

like image 94
dacwe Avatar answered Sep 22 '22 01:09

dacwe