Java

[Swing] BorderLayout

반나무 2020. 7. 4. 14:59

Swing의 기본 레이아웃은 BorderLayout이기 때문에 선언을 해주지 않아도 괜찮다.

 

package swing.frame;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class BorderLayoutFrame extends JFrame {

	public BorderLayoutFrame(String title) {
		
		//this없어도됨 //title설정
		setTitle(title);
		//size설정(width,height)
		setSize(300, 300);
		//위치 설정(x,y)
		setLocation(800, 300);
		
		//종료관리(보통 EXIT_ON_CLOSE를 사용, 상수3)
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JButton b1 = new JButton("1");
		add(b1,BorderLayout.NORTH);
		
		JButton b2 = new JButton("2");
		add(b2,BorderLayout.SOUTH);
		
		JButton b3 = new JButton("3");
		add(b3,BorderLayout.WEST);
		
		JButton b4 = new JButton("4");
		add(b4,BorderLayout.EAST);
		
		JButton b5 = new JButton("5");
		add(b5);
		
		this.setVisible(true);
	}
	
	public static void main(String[] args) {
		//인수로 넣음
		new BorderLayoutFrame("BorderLayout 프레임");
		
	}

}
반응형