Java Reference
In-Depth Information
After obtaining an array of
GraphicsConfiguration
s, an application can de-
terminewhetherit'srunninginasingle-screenenvironmentorinamultiscreenenviron-
ment.
MULTISCREEN ENVIRONMENTS
A
multiscreen environment
consistsoftwoormoreindependentscreens,twoormore
screenswhereonescreenisthedefaultandtheotherscreensdisplaycopiesofwhat
appears on the default screen, or two or more screens that form a
virtual desktop
,
which is also called a
virtual device
.
Figure 7-15
reveals a multiscreen environment.
Figure 7-15.
Each screen in this example has a resolution of 1024x768 pixels.
Whentwoormorescreensarecombinedintoavirtualdesktop,Java2Destablishes
a
virtual coordinate system
. This coordinate system exists outside of any screen's
bounds and is used to identify pixel coordinates within the virtual desktop.
Oneofthescreensisknownasthedefaultscreenanditsupper-leftcornerislocated
at (0, 0). If the default screen is not positioned in the upper-left corner of a grid of
screens,Java2Dmayrequireyoutousenegativecoordinates,asillustratedin
Figure
Theapplicationaccomplishesthistaskbycalling
Rectangle getBounds()
on
each
GraphicsConfiguration
returnedby
getConfigurations()
,andthen
checkingtoseeiftheoriginissomethingotherthan(0,0).
GraphicsConfigura-
tion
's
getBounds()
methodreturnsa
java.awt.Rectangle
instancewhose
x
,
y
,
width
, and
height
fields (of type
int
) reflect the virtual coordinate system. If
any (
x
,
y
) origin isn't (0, 0), the environment is a virtual device environment.
I've created an
IsVDE
application that determines if its environment is a virtual
device environment.
Listing 7-8
presents this application's source code.
Listing 7-8
. Detecting a virtual device environment