Hi
I am trying to complete q3 from this pdf. I have posted my program below, still now it draws middle line and the top box, but I think the label is not show and it off the screen. To me the program should work fine, do not know where the is going wrong. Please help me out.
Code:
public class ProgramHierarchy extends GraphicsProgram {
private static final int BOX_WIDTH = 100;
private static final int BOX_HEIGHT = 26;
private static final int MIDDLE_LINE_HEIGHT = 26;
private static final int GAP_BETWEEN_BOXES = 08;
public void run() {
placeMiddleLine();
placeTopBox();
}
private void placeMiddleLine() {
gl middleLine = new gl (getWidth()/2, (getHeight()/2) - (MIDDLE_LINE_HEIGHT)/2 , getWidth()/2, (getHeight()/2) + (MIDDLE_LINE_HEIGHT)/2);
add(middleLine);
}
private void placeTopBox() {
gr topBox = new gr ((getWidth()/2)-(BOX_WIDTH/2), ((getHeight()/2) - (BOX_HEIGHT)/2)-BOX_HEIGHT , BOX_WIDTH, BOX_HEIGHT);
add(topBox);
gla topLabel = new gla ("Program");
topLabel.setLocation((getWidth()/2) - (topLabel.getWidth()/2), (getHeight()/2) - (MIDDLE_LINE_HEIGHT/2) - (BOX_HEIGHT/2) + (topLabel.getAscent()/2));
add(topLabel);
}
}
Bookmarks