package com.swing;
import javax.swing.*;
import java.awt.*;
// GUI 화면을 만들어 보자. - 자바 표준 라이브러리
// 화면을 구성할 때 배치 관리자(layout)
// button 라벨, 텍스트 - 컴포넌트
public class FlowLayoutEx extends JFrame {
private JButton button1;
private JButton button2;
private JButton button3;
// 생성자
public FlowLayoutEx(){
super.setTitle("배치 관리자 연습 - FlowLayout");
super.setSize(500,500);
super.setVisible(true); // 화면에 보이게 한다. false, true
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 생성자 안에서 다른 메서드를 호출 할 수 있다.
initData();
setInitLayout();
}
public void initData(){
button1 = new JButton("button1");
button2 = new JButton("button2");
button2 = new JButton("버튼");
}
public void setInitLayout(){
// 배치 관리자 중 ... FlowLayout, BorderLayout, ... null(좌표기반)
super.setLayout(new FlowLayout());
// add 컴포넌트를 패널에 붙이다
super.add(button1);
super.add(button2);
super.add(button3);
}
// 코드 테스트
public static void main(String[] args) {
FlowLayoutEx flowLayoutEx = new FlowLayoutEx();
} // end of main
}
package com.swing;
import javax.swing.*;
public class BorderLayout extends JFrame {
public BorderLayout() {
setTitle("layout테스트");
setSize(200,200);
setVisible(true);
}
public static void main(String[] args) {
new BorderLayout();
}
}
'JAVA' 카테고리의 다른 글
object 클래스와 equals(), hashCode()메서드 (0) | 2025.04.26 |
---|---|
object 클래스와 toString() 메서드 (0) | 2025.04.26 |
인터페이스와 추상 클래스 활용한 코드 작성 (0) | 2025.04.26 |
인터페이스(interface) (1) | 2025.04.26 |
추상 클래스 구현해보기 (0) | 2025.04.26 |