즐거운프로그래밍

[자바] AWT 패키지의 이해(버튼 컴포넌트, Button Component)

수수께끼 고양이 2023. 10. 23. 14:26
728x90
반응형
import java.awt.*;
import java.awt.event.*;

public class Main {
    public static void main(String[] args) {
        Frame frame = new Frame();
        frame.setTitle("액자");
        frame.setBounds(100, 100, 600, 400);
        frame.setLayout(new FlowLayout());
        frame. setResizable(false);
        
        // 라벨 만들기
        Label label = new Label("문자열 : ");
        frame.add(label);
        
        // 버튼 만들기
        Button button = new Button("버튼");
        frame.add(button);
        
        // 완성된 윈도우 보이기
        frame.setVisible(true);

        // 윈도우 창 닫기 활성화
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
                System.exit(0);
            }
        });
    }
}

 

728x90
반응형