

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Based on a handout by Eric Roberts
Figure 1. Some useful methods in acm.graphics
Constructors new GLabel(String text) or new GLabel(String text, double x, double y) Creates a new GLabel object; the second form sets its location as well. new GRect(double x, double y, double width, double height) Creates a new GRect object; the x and y parameters can be omitted and default to 0. new GOval(double x, double y, double width, double height) Creates a new GOval object; the x and y parameters can be omitted and default to 0. new GLine(double x1, double y1, double x2, double y2) Creates a new GLine object connecting (x1, y1) and (x2, y2). Methods common to all graphical object void setLocation(double x, double y) Sets the location of this object to the specified coordinates. void move(double dx, double dy) Moves the object using the displacements dx and dy. double getWidth() Returns the width of the object. double getHeight() Returns the height of the object. void setColor(Color c) Sets the color of the object. Methods available for GRect and GOval only void setFilled(boolean fill) Sets whether this object is filled (true means filled, false means outlined). boolean isFilled() Returns true if the object is filled. void setFillColor(Color c) Sets the color used to fill this object. If the color is null, filling uses the color of the object. Methods available for GLabel only void setFont(String fontName) Sets the font, as described in Chapter 5. double getAscent() Returns the height above the baseline.