자바 AWT Layout 예제




/*
 * FlowLayout
 * 컴포넌트를 왼쪽,중앙,오른쪽으로 정렬하여 배치한다.
 */
import java.awt.*;

class Form extends Frame
{
 private Button bt1 =  new Button("버튼1"); // 버튼 컴포넌트
 private Button bt2 =  new Button("버튼2");
 private Button bt3 =  new Button("버튼3");
 private FlowLayout layout1 = new FlowLayout(FlowLayout.LEFT); // 레이아웃 메니저
 
 public Form(String title, int width, int height, boolean visible) {
  super(title);
  init();
  super.setSize(width, height);  // 프레임 크기
  
  Dimension screen =Toolkit.getDefaultToolkit().getScreenSize(); // 모니터화면의 해상도 얻기
  Dimension f1_size = super.getSize(); // 프레임크기
  
  // 프레임이 화면 중앙에 위치하도록 left, top 계산
  int left = (screen.width / 2) - (f1_size.width / 2);
  int top = (screen.height / 2) - (f1_size.height /2 );
  
  super.setLocation(left,  top); // left, top 설정
  super.setResizable(true); // 크기조절 불가능 설정
  super.setVisible(visible);  // 프레임이 보이도록 설정
 }
 
 public void init() {
  this.setLayout(layout1); // 레이아웃 설정
  this.add(bt1);  // 버튼 컴포넌트 추가
  this.add(bt2);
  this.add(bt3);
 }
}

public class FormTest {
 public static void main(String[] args) {
 
  Form f1 = new Form("FlowLayout 예제입니다.", 320, 240, true);
 }
}

 

a01-FlowLayout.png


 

 

 

 

 

/*
 * GridLayout
 * 행과 열을 설정하여 화면을 채우며 배치한다.
 */
import java.awt.*;

class Form extends Frame
{
 private Button bt1 =  new Button("버튼1"); // 버튼 컴포넌트
 private Button bt2 =  new Button("버튼2");
 private Button bt3 =  new Button("버튼3");
 private Button bt4 =  new Button("버튼4");
 private Button bt5 =  new Button("버튼5");
 private Button bt6 =  new Button("버튼6");
 private GridLayout layout1 = new GridLayout(3, 2, 10, 10); // 레이아웃 메니저(3행 2열, 20px 여백)
 
 public Form(String title, int width, int height, boolean visible) {
  super(title);
  init();
  super.setSize(width, height);  // 프레임 크기
  
  Dimension screen =Toolkit.getDefaultToolkit().getScreenSize(); // 모니터화면의 해상도 얻기
  Dimension f1_size = super.getSize(); // 프레임크기
  
  // 프레임이 화면 중앙에 위치하도록 left, top 계산
  int left = (screen.width / 2) - (f1_size.width / 2);
  int top = (screen.height / 2) - (f1_size.height /2 );
  
  super.setLocation(left,  top); // left, top 설정
  super.setResizable(true); // 크기조절 불가능 설정
  super.setVisible(visible);  // 프레임이 보이도록 설정
 }
 
 public void init() {
  this.setLayout(layout1); // 레이아웃 설정
  this.add(bt1);  // 버튼 컴포넌트 추가
  this.add(bt2);
  this.add(bt3);
  this.add(bt4);
  this.add(bt5);
  this.add(bt6);
 }
}

public class FormTest {
 public static void main(String[] args) {
 
  Form f1 = new Form("GridLayout 예제입니다.", 320, 240, true);
 }
}

 

a02-GridLayout.png


 

 

 

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

/*
 * BorderLayout
 * 컴포넌트를 5개의 방향으로 배치한다. (왼쪽, 오른쪽, 위, 아레, 중앙, 배치 형태)
 */
import java.awt.*;

class Form extends Frame
{
 private Button bt1 =  new Button("오른쪽"); // 버튼 컴포넌트
 private Button bt2 =  new Button("왼쪽");
 private Button bt3 =  new Button("아래쪽");
 private Button bt4 =  new Button("위쪽");
 private Button bt5 =  new Button("중앙");
 private BorderLayout layout1 = new BorderLayout(); // 레이아웃 메니저
 
 public Form(String title, int width, int height, boolean visible) {
  super(title);
  init();
  super.setSize(width, height);  // 프레임 크기
  
  Dimension screen =Toolkit.getDefaultToolkit().getScreenSize(); // 모니터화면의 해상도 얻기
  Dimension f1_size = super.getSize(); // 프레임크기
  
  // 프레임이 화면 중앙에 위치하도록 left, top 계산
  int left = (screen.width / 2) - (f1_size.width / 2);
  int top = (screen.height / 2) - (f1_size.height /2 );
  
  super.setLocation(left,  top); // left, top 설정
  super.setResizable(true); // 크기조절 불가능 설정
  super.setVisible(visible);  // 프레임이 보이도록 설정
 }
 
 public void init() {
  this.setLayout(layout1); // 레이아웃 설정
  this.add("East", bt1);  // 버튼 컴포넌트 추가
  this.add("West", bt2);
  this.add("South", bt3);
  this.add("North", bt4);
  this.add("Center", bt5);
 }
}

public class FormTest {
 public static void main(String[] args) {
 
  Form f1 = new Form("BorderLayout 예제입니다.", 320, 240, true);
 }
}

a03-BorderLayout.png


 

 


/*
 * GridBagLayout
 */
import java.awt.*;

class Form extends Frame
{
 private Button bt1 =  new Button("버튼1"); // 버튼 컴포넌트
 private Button bt2 =  new Button("버튼2");
 private Button bt3 =  new Button("버튼3");
 private Button bt4 =  new Button("버튼4");
 private Button bt5 =  new Button("버튼5");

 private GridBagLayout layout1 = new GridBagLayout(); // 레이아웃 메니저
 private GridBagConstraints gc = new GridBagConstraints();
 
 public Form(String title, int width, int height, boolean visible) {
  super(title);
  init();
  super.setSize(width, height);  // 프레임 크기
  
  Dimension screen =Toolkit.getDefaultToolkit().getScreenSize(); // 모니터화면의 해상도 얻기
  Dimension f1_size = super.getSize(); // 프레임크기
  
  // 프레임이 화면 중앙에 위치하도록 left, top 계산
  int left = (screen.width / 2) - (f1_size.width / 2);
  int top = (screen.height / 2) - (f1_size.height /2 );
  
  super.setLocation(left,  top); // left, top 설정
  super.setResizable(true); // 크기조절 불가능 설정
  super.setVisible(visible);  // 프레임이 보이도록 설정
 }
 
 public void init() {
  this.setLayout(layout1); // 레이아웃 설정
  gc.gridx = 0;
  gc.gridy = 0;
  layout1.setConstraints(bt1, gc);
  this.add(bt1);
  
  gc.gridx = 1;
  gc.gridy = 0;
  layout1.setConstraints(bt2, gc);
  this.add(bt2);

  gc.gridx = 1;
  gc.gridy = 1;
  layout1.setConstraints(bt3, gc);
  this.add(bt3);
  
  gc.gridx = 2;
  gc.gridy = 1;
  layout1.setConstraints(bt4, gc);
  this.add(bt4);

 }
}

public class FormTest {
 public static void main(String[] args) {
 
  Form f1 = new Form("GridBagLayout 예제입니다.", 320, 240, true);
 }
}

 

a04-GridBagLeyout.png





[출처] http://sugame.tistory.com/617


본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
30 Java XML Parse, Java XML 파싱 샘플 졸리운_곰 2015.03.03 814
29 Java Inner class 자바 중첩(내부)클래스 졸리운_곰 2015.03.03 886
28 IzPack으로 GUI 설치 프로그램 만들기 file 졸리운_곰 2015.02.15 638
» [Java],[AWT],[Layout],[AWT Layout], file 졸리운_곰 2015.02.13 368
26 [Java],[AWT],[SWING], Java GUI file 졸리운_곰 2015.02.13 922
25 [Java][AWT 개요] file 졸리운_곰 2015.02.13 463
24 javac 로 컴파일 시 유니코드(utf-8) 한글 소스 코드 컴파일 문제 졸리운_곰 2015.02.02 1133
23 [스프링] 스프링 Java 어노테이션 file 졸리운_곰 2014.06.11 960
22 [스프링] 스프링 MVC 졸리운_곰 2014.06.11 532
21 [스프링] 어노테이션 졸리운_곰 2014.06.11 1032
20 인코딩 - 8859_1의 비밀(?) file 졸리운_곰 2014.05.06 581
19 [JNI] 안드로이드 JNI 환경에서 C++과 Java 간의 한글 데이터 전송 문제 졸리운_곰 2014.05.06 597
18 자바 암호화 복호화 file 졸리운_곰 2014.04.08 2495
17 파일 존재 여부 판단, 디렉토리 있는지 확인 함수; File Directory Exist 졸리운_곰 2014.03.03 1215
16 NetStat call and get result text in Java 졸리운_곰 2014.02.25 903
15 [Spring] @Autowired 와 Java Spring 졸리운_곰 2014.01.29 1332
14 Java Static 변수 졸리운_곰 2014.01.28 1102
13 Properties 클래스 사용하기. 졸리운_곰 2014.01.28 1024
12 Java => Thread 졸리운_곰 2014.01.28 834
11 [Spring] 내가 Spring을 사랑하는 다섯 가지 이유 file 가을의 곰을... 2013.12.22 970
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED