자바 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


본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
18 [java 인공지능] Spring AI 로 ChatGPT API 만들기 졸리운_곰 2024.12.30 215
17 [java 인공지능] 오라클, 자바 머신러닝 라이브러리 ‘트리뷰오’ 오픈소스로 공개 졸리운_곰 2023.08.27 296
16 [java 인공지능] 자바를 위한 머신 러닝 라이브러리 졸리운_곰 2023.08.27 361
15 [Java 인공지능] 오라클, 자바 머신러닝 라이브러리 ‘트리뷰오’ 오픈소스로 공개 file 졸리운_곰 2023.08.13 358
14 [java 인공지능] [java] 라이프 게임 (life game) file 졸리운_곰 2021.10.19 341
13 How to use Weka in your Java code 졸리운_곰 2020.02.01 307
12 weka and java eclipse example : A Simple Machine Learning Example in Java file 졸리운_곰 2020.01.31 365
11 머신러닝? weka file 졸리운_곰 2020.01.31 358
10 [Weka] Weka를 이용한 Iris 데이터 머신러닝 file 졸리운_곰 2020.01.30 365
9 [강좌] WEKA 사용법 (간단한 분류, 의사결정트리 분석 설명) file 졸리운_곰 2020.01.30 344
8 [JESS] Jess , 이클립스 연동 file 졸리운_곰 2019.12.22 217
7 Jess 간단한 문법 요약 졸리운_곰 2019.12.22 278
6 Jess 6.1 다운로드 friedman-hill_src_1_jess_se file 졸리운_곰 2019.12.22 187
5 java artificial intelligence Rule Engine Jess Working Memory 졸리운_곰 2019.12.22 301
4 Defining Functions in Jess 졸리운_곰 2019.12.22 389
3 Jess Language Basics 졸리운_곰 2019.12.22 274
2 Embedding Jess in a Java Application 졸리운_곰 2019.12.22 300
1 다섯개의 탑 자바로 머신러닝 라이브러리 Top 5 machine learning libraries for Java file 졸리운_곰 2017.08.22 389
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED