728x90
728x90
코드
public class MyFramePanel extends JFrame {
JButton[] buttons = new JButton[6];
private JPanel panel1;
private JPanel panel2;
public MyFramePanel2() {
initData();
setInitLayout();
}
private void initData() {
setTitle("패널 연습");
setSize(600, 400);
setDefaultCloseOperation(3);
panel1 = new JPanel();
panel1.setBackground(Color.red);
panel2 = new JPanel();
panel2.setBackground(Color.yellow);
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton("버튼 " + (i + 1));
}
}
private void setInitLayout() {
add(panel1, BorderLayout.CENTER);
panel1.setLayout(new FlowLayout(FlowLayout.LEFT));
add(panel2, BorderLayout.SOUTH);
panel2.setLayout(new FlowLayout(FlowLayout.RIGHT));
for (int j = 0; j < 3; j++) {
panel1.add(buttons[j]);
}
for (int h = 3; h < buttons.length; h++) {
panel2.add(buttons[h]);
}
setVisible(true);
}
public static void main(String[] args) {
new MyFramePanel();
}
}
실행
320x100
반응형
'Java > Swing (GUI)' 카테고리의 다른 글
[Java/Swing] paint 메서드 : 도형, 이미지, 문자열 그리기 (0) | 2023.02.14 |
---|---|
[Java/Swing] 패널 (Panel) (0) | 2023.02.14 |
[Java/Swing] 컴포넌트 (Component) (0) | 2023.02.14 |
[Java/Swing] 배치 관리자 (Layout) (0) | 2023.02.14 |
[Java/Swing] 배치 관리자 3 - NoLayout 구현 (0) | 2023.02.14 |