I am trying to learn java using Stanford's online CS106A course. The course uses the acm library packages from http://jtf.acm.org/
Can anyone tell me why is my code below doesn't centered the label along the y axis?
import acm.program.*;
import acm.graphics.*;
public class CenterLabel extends GraphicsProgram {
public void run() {
GLabel text = new GLabel("HELLO!");
text.setFont("Arial-200");
double cy = (getHeight() / 2) + (text.getAscent() / 2);
text.setLocation(0, cy);
add(text);
}
}
When I run this program I get this: https://i.stack.imgur.com/9U4L8.jpg
Edit: Another thing that's troubling me is that the sample run in the assignment also seem to have the same alignment problem. (See link below, Ex3)
http://see.stanford.edu/materials/icspmcs106a/13-assignment-2-simple-java.pdf
If you look at the picture carefully, you can see that the label inside the class box is also not centered properly?