import acm.graphics.;
import acm.program.;
public class GraphicsHierarchy extends GraphicsProgram {
//width of each box in the picture
private static final int Width = 150;
// height of each box in the picture
private static final int Height = 60;
public void run() {
int n = 4 ;
drawGObjectBox();
drawGLabelBox();
drawGLineBox();
drawGOvalBox();
drawGRectBox();
drawLine1();
drawLine2();
drawLine3();
drawLine4();
}
private void drawBox() {
int x = getWidth()/n - Width()/2;
int y = getHeight()/n - Heigth()/2;
for(int i=0; i < n; i++ ) {
}
}
private void drawGObjectBox() { // object 상자 그리기
int x = getWidth()/2 - Width/2; // 상자의 x위치는 정중앙에서 상자의 너비의 반만큼 왼쪽으로 간 곳에서 시작한다.
int y = getHeight()/2 - Height; // 상자의 y위치는 정중앙에서 상자의 높이의 반만큼 위로 간 곳에서 시작한다.
GRect drawBox = new GRect (x, y, Width, Height);
add(drawBox); // object 상자 그리기
GLabel gobject = new GLabel("GObject", x, y);
add(gobject); // "GObject"이라는 라벨을 붙인다.
double boxCenterX = Width/2;
double boxCenterY = Height/2;
double halfGObjectWidth = gobject.getWidth()/2; // object 상자의 길이를 얻느다.
double halfGObjectHeight = gobject.getAscent()/2; // object 상자의 높이를 얻는다.
gobject.move( (boxCenterX - halfGObjectWidth) , (boxCenterY + halfGObjectHeight) );
}
private void drawGLabelBox() {
int x = getWidth()/n - Width;
int y = getHeight()/2 + Height;
GRect drawBox = new GRect (x, y, Width, Height);
add(drawBox);
GLabel glabel = new GLabel ("GLabel", x, y);
add(glabel);
double boxCenterX = Width / 2;
double boxCenterY = Height / 2;
double halfGLabelWidth = glabel.getWidth()/2;
double halfGLabelHeight = glabel.getAscent()/2;
glabel.move( (boxCenterX - halfGLabelWidth) , (boxCenterY + halfGLabelHeight) );
}
private void drawGLineBox() {
int x = getWidth()/n*3 - Width;
int y = getHeight()/2 + Height;
GRect drawBox = new GRect (x, y, Width, Height);
add(drawBox);
GLabel gline = new GLabel ("GLine", x, y);
add(gline);
double boxCenterX = Width / 2;
double boxCenterY = Height / 2;
double halfGLineWidth = gline.getWidth()/2;
double halfGLineHeight = gline.getAscent()/2;
gline.move( (boxCenterX - halfGLineWidth) , (boxCenterY + halfGLineHeight) );
}
private void drawGOvalBox() {
int x = getWidth()/n*5 + Width;
int y = getHeight()/2 + Height;
GRect drawBox = new GRect (x, y, Width, Height);
add(drawBox);
GLabel goval = new GLabel ("GOval", x, y);
add(goval);
double boxCenterX = Width / 2;
double boxCenterY = Height / 2;
double halfGOvalWidth = goval.getWidth()/2;
double halfGOvalHeight = goval.getAscent()/2;
goval.move( (boxCenterX - halfGOvalWidth) , (boxCenterY + halfGOvalHeight) );
}
private void drawGRectBox() {
int x = getWidth()/n*7 + Width;
int y = getHeight()/2 + Height;
GRect drawBox = new GRect (x, y, Width, Height);
add(drawBox);
GLabel grect = new GLabel ("GRect", x, y);
add(grect);
double boxCenterX = Width / 2;
double boxCenterY = Height / 2;
double halfGRectWidth = grect.getWidth()/2;
double halfGRectHeight = grect.getAscent()/2;
grect.move( (boxCenterX - halfGRectWidth) , (boxCenterY + halfGRectHeight) );
}
private void drawLine1() {
int x1 = getWidth()/2; // 너비를 찾는다.
int y1 = getHeight()/2; // 높이를 찾는다.
int x2 = getWidth()/2;
int y2 = getHeight()/2 + Height; //finds end point for height
GLine drawLine = new GLine (x1, y1, x2, y2);
add(drawLine);
}
private void drawLine2() {
int x1 = getWidth()/4;
int y1 = getHeight()/2;
int x2 = getWidth()/4 - 4 * (Width/2);
int y2 = getHeight()/2 + Height;
GLine drawLine = new GLine (x1, y1, x2, y2);
add(drawLine);
}
private void drawLine3() {
int x1 = getWidth()/2;
int y1 = getHeight()/2;
int x2 = getWidth()/2 + 3 * (Width/2);
int y2 = getHeight()/2 + Height;
GLine drawLine = new GLine (x1, y1, x2, y2);
add(drawLine);
}
private void drawLine4() {
int x1 = getWidth()/2;
int y1 = getHeight()/2;
int x2 = getWidth()/2 + 3 * (Width/2);
int y2 = getHeight()/2 + Height;
GLine drawLine = new GLine (x1, y1, x2, y2);
add(drawLine);
}
}