
Untitled
By: a guest on
Apr 15th, 2012 | syntax:
None | size: 0.57 KB | hits: 12 | expires: Never
Why is my label not centered along the y axis? (Stanford SEE CS106A)
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);
}
}
text.setBounds(20,20,20,20);
double cy = (getHeight() / 2) - (text.getAscent() / 2);
public static void main(String[] args) {
new /* name of your class */.start(args);
}