K-DigitalTraining 강의/1. Java
[5주차] 92. AWT, BorderLayout 배치 예시 코드
이대곤
2022. 6. 8. 17:35
import java.awt.*;
class Sub1 extends Frame{
Sub1(String title){
super(title); // 부모의 생성자에 넘겨주면 제목을 보여지게 할 수 있음
super.setSize(400,300); //setSize(400,300);
Button east_bt = new Button("동쪽");
Button west_bt = new Button("서쪽");
Button south_bt = new Button("남쪽");
Button north_bt = new Button("북쪽");
Button center_bt = new Button("중앙");
setLayout(new BorderLayout()); // BorderLayout 사용시 아래와 같이 동서남북센터 위치를 지정해주지 않으면 전부다 Center로 지정이 되어서 다른게 겹쳐서 안보이는 경우가 발생함
add("East", east_bt);
add("West", west_bt);
add("South", south_bt);
add("North", north_bt);
add("Center", center_bt);
// 다음과 같은 방식으로도 가능
//add(center_bt, BorderLayout.CENTER);
}
}
public class Ex12_02_Button {
public static void main(String[] args) {
Sub1 f = new Sub1("버튼만들기"); // 다형성에 의해 Frame f = new Sub1("버튼만들기"); 이것도 가능
f.setVisible(true);
}
}