Java Reference
In-Depth Information
￿ Toolkit.getDefaultToolkit().getScreenSize()
Returns the dimension of the
display in pixels.
￿ Color
The class for colors.
Creates an object for the red color.
Color c = Color.RED;
Creates a new color with red=3, green=4, and
Color c = new Color(2,3,4);
Returns the background color of the panel.
Changes the background color of the panel
to red.
The drawing brush class.
The 2D drawing brush class, which inherits from the Graphics class.
￿ Font f = new Font("SansSerif",Font.Bold+Font.Italic,20);
Creates a new
font object with font: SansSerif, bold and italic, and 20-point size.
￿ GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFami-
Returns an array of the names of all available fonts that are currently
installed in the operating system.
￿ g2.setColor(;
Changes the color of the brush to red, where g2 is an
object of type Graphics2D .
￿ g2.setFont(f);
Changes the font of the brush.
Draws the string s with bottom left position of (10,20).
Draws a rectangle starting
g2.draw(new Rectangle2D.Double(2,2,10,20));
with top left corner of (2,2) of width 10 and height 20.
Fills a rectangle starting with
g2.fill(new Rectangle2D.Double(2,2,10,20));
top left corner of (2,2) of width 10 and height 20.
g2.draw(new Ellipse2D.Double(2,2,10,20));
Draws an ellipse with surround-
ing rectangle with top left corner of (2,2) of width 10 and height 20.
Draws a line between the pixels (2,2)
g2.draw(new Line2D.Double(2,2,10,20));
and (10,20).
￿ g2.draw(new Point2D.Double(2,2));
Displays the point (2,2).
￿ Image image = File("player.gif"));
Creates an image ob-
jet from gif file.
￿ g2.drawImage(image,10,10);
Draws the image at position (10,10).
￿ System.exit(0);
Terminates the program.
Search WWH ::

Custom Search