Swing

swing - 1

whs5758 2025. 4. 23. 17:49
package com.swing;

import javax.swing.*;
import java.awt.*;

// GUI 화면을 만들어 보자 - 자바 표준 라이브러리
// 화면을 구성할 때 배치 관리자(layout)
// button, label, text - 컴포넌트
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 - 보이지 않음
        super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // 생성자 안에서 다른 메서드를 호출 할 수 있다.
        initData();
        setInitLayout();
    }

    public void initData() {
        button1 = new JButton("button1");
        button2 = new JButton("button2");
        button3 = new JButton("버튼");
    }

    public void setInitLayout() {
        // 배치관리자 중 ... FlowLayout, BorderLayout, ... null (좌표기반)
        // FlowLayout -> 컴포넌트들을(버튼) 수평, 수직으로 배치하는 객체입니다.
        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

}

'Swing' 카테고리의 다른 글

이미지 올려보기  (1) 2025.04.28
패널 사용해보기  (0) 2025.04.28
좌표값으로 컴포넌트 배치해보기  (0) 2025.04.28
기본 컴포넌트 소개  (0) 2025.04.28
BorderLayout 과 배열의 활용  (0) 2025.04.28