Java Reference
In-Depth Information
Then you access the new system property as follows:
String some - value =
System.getProperty ("some.env.variable");
Obviously, you can name the system property anything you want.
Information on the platform display is available from the java.awt.
Toolkit ,which we used in Section 6.9 to obtain images and in Section 12.2 to
obtain instances of PrintJob . The method
int getScreenResolution ()
returns the resolution in dots-per-inch. (Unfortunately, on Windows systems the
value returned is actually the font size setting rather than the screen resolution
setting.) The method
Dimension getScreenSize ()
returns the width and height of the screen in pixels. For example, you can use
this to set the location of a frame at the center of the screen with a method
like this:
public void center () {
Dimension screenSize =
Toolkit.getDefaultToolkit ().getScreenSize ();
Dimension frameSize = getSize ();
int x = (screenSize.width - frameSize.width) / 2;
int y = (screenSize.height - frameSize.height) / 2;
setLocation (x, y);
}
Finally, the colors of the systems GUI are available from the class java.
awt.SystemColor .For example, you can use it to coordinate the colors in
your interface to those of the underlying platform system colors with commands
like myCanvas.setBackground(SystemColor.window) .
23.3 Running external programs
There are situations in which a Java application needs to run non-Java programs
on the platform where it resides. A common example involves opening a browser
when the user selects a web link in the interface as might occur, for example, by
clicking on a help button. Another example is the case of a server running on
a remote device (see Chapters 14 and 15) that starts a non-Java program, e.g. a
diagnostic test, at the request of a client.
The Runtime and Process classes (both part of java.lang ) are available
for launching and communicating with external programs. The following example
Search WWH ::




Custom Search