|
|
||
Artem Ananiev's BlogHeadless toolkit basicsPosted by ixmal on April 04, 2006 at 10:15 AM | Comments (5)Toolkitjava.awt.Toolkit is an abstract superclass of all actual implementations of the Abstract Window Toolkit (AWT). Subclasses of java.awt.Toolkit are used to bind various components to particular native resources.You may have noticed that many of the methods in java.awt.Toolkit, java.awt.GraphicsEnvironment and other classes require the availability of display, keyboard and mouse. You may easily find such methods as they throw java.awt.HeadlessException in headless mode.What is that headless mode? Headless modeHeadless mode is a system configuration in which graphic adapter, keyboard or mouse are lacking. For example, mainframes or dedicated servers do not support a display, keyboard or mouse. On the other hand, such environments possess a substantial computing power, which can be used for the non-visual features realization.All the AWT components with the exception of Canvas and Panel can not be operated in Headless mode. These include: applets, buttons, checkboxes, choices, dialogs, file dialogs, frames, labels, lists, menus, menubars, popup menus, page and print dialogs, scrollbars, scrollpanes, text components, windows, and their descendants. Such heavyweight components require a native "peer" at the operating system level, which cannot be guaranteed on "headless" machines.Here is a brief list of what is available in Headless mode: * lightweight components: canvas, panels, Swing components (with the exception of JApplet, JDialog, JFrame and JWindow) * fonts and font metrics * colors * images * printing using java.awt.PrintJob, java.awt.print.* and javax.print.** audio beep Headless mode setupTo set up the Headless mode you should set the appropriate system property usingSystem.setProperty() method. Property name is "java.awt.headless" and possible values are "true" or "false". Note, that this property shoult be set before the toolkit is initialized with Toolkit.getDefaultToolkit() method.To check up the availability of the Headless mode you should use GraphicsEnvironment.isHeadless() method. This method checks the "java.awt.headless" property: if it equals to "true", it is assumed that java.awt.HeadlessException will be thrown from all the methods that are dependent on a display, keyboard, or mouse. This method *does not check* hardware configuration of the system, so it is possible to run the application in the Headless mode on a usual desktop.ExampleAll the capabilities described above are represented in the integrated HeadlessBasics example. There are some comments in the source code to better understang Headless mode basics.Compile the source code using javac compiler. Download grapefruit.jpg image and put it to the directory where the HeadlessBasics class is located and then run the example with `java HeadlessBasics`. You can run it without any display, keyboard or mouse in the system, for example, using a remote console. Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment
| ||
|
|