Written by Eric Roberts and Lisa Yan
Here are the most common graphics commands:
Some other helpful graphics commands:
getWidth(); // returns the width of the screen.
getHeight(); // returns the height of the screen.
add(object); // adds an object to the screen.
add(object, x, y); // adds an object to the screen at coordinates (x, y).
remove(object); // removes an object from the screen.
getElementAt(x, y); // returns the element at (x, y).
Recall that setLocation(x,y) sets the origin of a GRect, GOval, or GLine to the coordinates (x,y), where the origin is defined as the top-left corner. GLabel has the same definition of origin, but the height is defined a bit taller than the actual text height. Here is a detailed look at all the different height definitions for GLabel:
The origin of a GLabel, however, is at the bottom-left of the first line in the label (including if it is a one line label).
So to center a one-line GLabel vertically, we would actually use the ascent of a GLabel:
double y = getHeight()/2 + label.getAscent()/2;
You can also upload your own images and add them to your graphics program!
A few tips: