Java Reference
In-Depth Information
return;
}
}
System.out.println("no virtual device environment
detected");
}
}
}
Assuming that the environment is a virtual device environment, you can create
Frame , javax.swing.JFrame , Window ,or javax.swing.JWindow contain-
erwindowsthatrefertodifferentgraphicsdevicesbycallingappropriateconstructors,
such as Frame(GraphicsConfiguration gc) .
Inamultiscreenenvironmentinwhichthedesktopareacouldspanmultiplephysical
screendevices,theboundsof GraphicsConfiguration objectsarerelativetothe
virtualcoordinatesystem.Whensettingthelocationofacomponentinthiscoordinate
system,use getBounds() togettheboundsofthedesired GraphicsConfigur-
ation and offset the location with these coordinates, as the following example illus-
trates:
Frame f = new Frame(gc); // Assume gc is a GraphicsConfig-
uration instance.
Rectangle bounds = gc.getBounds();
f.setLocation(10+bounds.x, 10+bounds.y);
Graphics2D
Java 2D's abstract Graphics2D class (a Graphics subclass) describes a logical
drawing surface on which graphics primitives (2D shapes [such as rectangles and el-
lipses], text, and images) are drawn.
The logical drawing surface is associated with user space , which is a 2D Cartesian
(x/y)planewhosepixelsareknownas logical pixels ,andwhichhavefloating-pointco-
ordinates.Asaresult,various Graphics2D methodsacceptfloating-pointcoordinate
values;forexample, void drawString(String str, float x, float y) .
WhilediscussingAWTgraphics,Ipreviouslymentionedthata Graphics subclass
instance is passed to a component's paint() method. Prior to Java 1.2, this was
alwaysthecase.StartingwithJava1.2,a Graphics2D subclassinstanceispassedto
Search WWH ::




Custom Search