<4D F736F F F696E74202D20C1A63139C0E520B9E8C4A120B0FCB8AEC0DA28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Similar documents
PowerPoint Presentation

PowerPoint Presentation

gnu-lee-oop-kor-lec10-1-chap10

<4D F736F F F696E74202D20C1A63233C0E520B1D7B7A1C7C820C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

9장.key

<4D F736F F F696E74202D20C1A63138C0E520C0CCBAA5C6AE20C3B3B8AE28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

<4D F736F F F696E74202D20C1A63230C0E520BDBAC0AE20C4C4C6F7B3CDC6AE203128B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Microsoft PowerPoint - java1-lecture10.ppt [호환 모드]

강의자료

<4D F736F F F696E74202D20C1A63236C0E520BED6C7C3B8B428B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Microsoft PowerPoint - 04-UDP Programming.ppt

11장.key

No Slide Title

Microsoft PowerPoint - ÀÚ¹Ù08Àå-1.ppt

Microsoft PowerPoint - 14주차 강의자료

No Slide Title

10장.key

Microsoft PowerPoint - EEL2 Lecture10 -Swing and Event Handling.pptx

제8장 자바 GUI 프로그래밍 II

public class FlowLayoutPractice extends JFrame { public FlowLayoutPractice() { super("flowlayout Practice"); this. Container contentpane = getcontentp

슬라이드 1

모든스윙컴포넌트에는텍스트옆에이미지를추가로표시할수있다. ImageIcon image = new ImageIcon("image.gif"); JLabel label = new JLabel(" 이미지레이블 "); label.seticon(image);

자바GUI실전프로그래밍2_장대원.PDF

Microsoft PowerPoint - Java-03.pptx

PowerPoint Presentation

Microsoft PowerPoint - [JAVA프로그래밍]9장GUI

Microsoft PowerPoint - ÀÚ¹Ù08Àå-2.ppt

Java Programing Environment

PowerPoint Presentation

(Microsoft PowerPoint - java1-lecture7.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - LZVNQBAJWGTC.ppt [\310\243\310\257 \270\360\265\345])

PowerPoint Presentation

슬라이드 1

Chap12

05-class.key

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Microsoft PowerPoint - java1-lecture11.ppt [호환 모드]

JTable과 MVC(Model-View-Controller) 구조 - 모델-뷰-컨트롤러구조는데이터의저장과접근에대한제공은모델이담당하고, 화면표시는뷰, 이벤트의처리는컨트롤러가하도록각역할을구분한구조이다. 즉, 역할의분담을통하여상호간의영향을최소화하고각요소의독립성을보장하여독자

Cluster management software

Microsoft PowerPoint - 06-Chapter09-Event.ppt

10-Java Applet

오버라이딩 (Overriding)

Microsoft PowerPoint - java2-lecture5.ppt [호환 모드]

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

PowerPoint Presentation

슬라이드 1

Cluster management software

rmi_박준용_final.PDF

Microsoft PowerPoint - java1-lecture11.ppt [호환 모드]

Microsoft PowerPoint 자바-AWT컴포넌트(Ch8).pptx

11-GUI.key

중간고사

쉽게 풀어쓴 C 프로그래밍

Microsoft PowerPoint - Java7.pptx

Cluster management software

PowerPoint Presentation

PowerPoint 프레젠테이션

Design Issues

ch09

02 C h a p t e r Java

JMF3_심빈구.PDF

(Microsoft PowerPoint - java2-lecture6.ppt [\310\243\310\257 \270\360\265\345])

웹연동 } 웹 (Web) 환경에서데이터베이스시스템을연동하는방법은다음과같다 } Server Client 구조의통신 (2-Tier) } Server Middleware Client 구조의통신 (3-Tier) 2

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

Microsoft Word - java18-1-final-answer.doc

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

PowerPoint 프레젠테이션

Microsoft PowerPoint - java2-lecture6.ppt [호환 모드]

쉽게 풀어쓴 C 프로그래밍

Spring Boot

PowerPoint Presentation

Spring Data JPA Many To Many 양방향 관계 예제

DB 에데이터저장을위한입력창설계 - JLabel, JTextField, JButton 을이용한입력창설계 - 2 -

gnu-lee-oop-kor-lec06-3-chap7

쉽게 풀어쓴 C 프로그래밍

Spring Boot/JDBC JdbcTemplate/CRUD 예제

<4D F736F F F696E74202D20C1A63234C0E520C0D4C3E2B7C228B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

비긴쿡-자바 00앞부속

PowerPoint Presentation

Network Programming

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1"); void method() 2"); void method1() public class Test 3"); args) A

JAVA PROGRAMMING 실습 08.다형성

PowerPoint 프레젠테이션

제11장 프로세스와 쓰레드

쉽게 풀어쓴 C 프로그래밊

쉽게

PowerPoint 프레젠테이션

PowerPoint Presentation

PowerPoint 프레젠테이션

10 이벤트 처리와 그래픽 프로그래밍.key

09-interface.key

PowerPoint Presentation

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D3130C0E5C0CCBAA5C6AEC3B3B8AE>

PowerPoint 프레젠테이션

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

<4D F736F F F696E74202D20C1A63235C0E520B3D7C6AEBFF6C5A920C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

PowerPoint 프레젠테이션

WS12. Security

12-file.key

Transcription:

Power Java 제 19 장배치관리자 이번장에서학습할내용 배치관리자의개요 배치관리자의사용 FlowLayout BorderLayout GridLayout BoxLayout CardLayout 절대위치로배치 컨테이너안에서컴포넌트를배치하는방법에대하여살펴봅시다.

배치관리자 (layout manager) 컨테이너안의각컴포넌트의위치와크기를결정하는작업 [3/70] 상당히다르게보인다. 배치관리자에따라서상당히다르게보인다. [4/70]

배치관리자의종류 BorderLayout BoxLayout CardLayout 배치관리자의종류 FlowLayout GridBagLayout GidL GridLayout

배치관리자의설정 1. 생성자를이용하는방법 JPanel panel = new JPanel(new BorderLayout()); 2. setlayout() 메소드이용 panel.setlayout(new FlowLayout()); 크기와정렬힌트 프로그래머가컴포넌트의크기와힌트를배치관리자에게주고싶은경우에는 setminimumsize(), setpreferredsize(), setmaximumsize() 메소드를사용 ( 예 ) component.setmaximumsize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE));

FlowLayout 컴포넌트들을왼쪽에서오른쪽으로버튼을배치한다. 패널과애플릿의디폴트배치관리자이다. import java.awt.*; import javax.swing.*; FlowLayout 예제 class MyFrame extends JFrame { public MyFrame() { settitle("flowlayouttest"); t") setdefaultcloseoperation(jframe.exit_on_close); JPanel panel; // 패널을생성하고배치관리자를 FlowLayout으로설정 panel = new JPanel(); panel.setlayout(new FlowLayout(FlowLayout.CENTER)); // 패널에버튼을생성하여추가 panel.add(new JButton("Button1")); panel.add(new JButton("Button2")); panel.add(new JButton("Button3")); panel.add(new JButton("B4")); panel.add(new JButton("Long Button5")); add(panel); pack(); setvisible(true);

BorderLayout BorderLayout 은 5 개의영역으로구분하고각각의영역에컴포넌트를배치 PAGE_START ( 또는 NORTH) PAGE_END ( 또는 SOUTH) LINE_START ( 또는 WEST) LINE_END END ( 또는 EAST) CENTER import java.awt.*; import javax.swing.*; BorderLayout 예제 class MyFrame extends JFrame { public MyFrame() { settitle("borderlayouttest"); t") setdefaultcloseoperation(jframe.exit_on_close); // 프레임은디폴트로 BorderLayout 이므로사실은불필요 setlayout(new BorderLayout()); // 버튼을추가한다. add(new JButton("Center"), t ") BorderLayout.CENTER); tcenter) add(new JButton("Line Start"), BorderLayout.LINE_START); add(new JButton("Line End"), BorderLayout.LINE_END); add(new JButton("Page Start"), BorderLayout.PAGE_START); _ add(new JButton("Page End"), BorderLayout.PAGE_END); pack(); setvisible(true);

GridLayout GridLayout 은컴포넌트들을격자모양으로배치한다. import java.awt.*; import javax.swing.*; GridLayout 예제 class MyFrame extends JFrame { public MyFrame() { settitle("gridlayouttest"); idl t") setdefaultcloseoperation(jframe.exit_on_close); setlayout(new GridLayout(0, 3)); // 3 개의열과필요한만큼의행 add(new JButton("Button1")); add(new JButton("Button2")); add(new JButton("Button3")); add(new JButton("B4")); add(new JButton("Long Button5")); pack(); setvisible(true);

BoxLayout BoxLayout은컴포넌트를다른컴포넌트위에쌓거나컴포넌트를하나의행에배치할수있다. BoxLayout은 FlowLayout의하나의버전으로간주할수있으나좀더기능이많다. import java.awt.*; import java.awt.event.*; import javax.swing.*; BoxLayout 예제 class MyFrame extends JFrame { public MyFrame() { settitle("boxlayouttest"); setdefaultcloseoperation(jframe.exit_on_close); JPanel panel = new JPanel(); // Y 축방향으로컴포넌트를쌓는다. panel.setlayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); makebutton(panel, "Button1"); makebutton(panel, "Button2"); makebutton(panel, "Button3"); makebutton(panel, "B4"); makebutton(panel, "Long Button5"); add(panel); pack(); setvisible(true);

GridLayout 예제 private void makebutton(jpanel panel, String text) { JButton button = new JButton(text); button.setalignmentx(component.center_alignment); ALIGNMENT); panel.add(button); CardLayout CardLayout 클래스는여러개의카드가쌓여있는형태로컴포넌트를배치

import java.awt.*; import java.awt.event.*; import javax.swing.*; CardLayout 예제 class MyFrame extends JFrame implements ActionListener { JPanel panel; Cards cards; public MyFrame() { settitle("cardlayouttest"); setsize(400, 200); setdefaultcloseoperation(jframe.exit_on_close); panel = new JPanel(new GridLayout(0, 5, 10, 0)); addbutton("<<", " panel); addbutton("<", panel); addbutton(">", panel); addbutton(">>", panel); addbutton(" 종료 ", panel); add(panel, "North"); cards = new Cards(); add(cards, "Center"); setvisible(true); CardLayout 예제 void addbutton(string str, Container target) { JButton button = new JButton(str); button.addactionlistener(this); target.add(button); private class Cards extends JPanel { CardLayout layout; public Cards() { layout = new CardLayout(); setlayout(layout); for (int i = 1; i <= 10; i++) { add(new JButton(" 현재카드의번호는 " + i + " 입니다 "), "Center"); ")

CardLayout 예제 public void actionperformed(actionevent e) { if (e.getactioncommand().equals(" 종료 ")) { System.exit(0); else if (e.getactioncommand().equals("<<")) { cards.layout.first(cards); else if (e.getactioncommand().equals("<")) { cards.layout.previous(cards); d else if (e.getactioncommand().equals(">")) { cards.layout.next(cards); else if (e.getactioncommand().equals(">>")) () ( )) { cards.layout.last(cards); public class CardTest { public static void main(string args[]) { MyFrame f=new MyFrame(); GridLayout 예제

어떤배치관리자를선택할것인가? 컴포넌트를가능한크게나타내고싶은경우 GridLayout 이나 BorderLayout 을사용 몇개의컴포넌트를자연스러운크기로한줄로나타내고싶은경우 FlowLayout을사용하던지 BoxLayout을사용한다. 몇개의컴포넌트를행과열로동일한크기로나타내고싶은경우 GridLayout을사용하여야한다. 몇개의컴포넌트를행과열로나타내는데각컴포넌트의크기가다르거나간격, 정렬방식을다르게내고싶은경우 BoxLayout 을사용하면된다. 절대위치로배치하기 1. 배치관리자를 null로설정한다. setlayout(null); 2. add() 메소드를사용하여컴포넌트를컨테이너에추가한다. Button b = Button("Absolute Position Button"); add(b); 3. setbounds() 메소드를사용하여절대위치와크기를지정한다. b.setbounds(x, y, w, h); 4. 컴포넌트의 repaint() 메소드를호출한다. b.repaint();

import java.awt.*; import java.awt.event.*; import javax.swing.*; class MyFrame extends JFrame { JButton b1; private JButton b2, b3; CardLayout 예제 public MyFrame() { settitle("absolute Position Test"); setdefaultcloseoperation(jframe.exit_on_close); setsize(300, 200); JPanel p = new JPanel(); p.setlayout(null); t( b1 = new JButton("Button #1"); p.add(b1); b2 = new JButton("Button #2"); p.add(b2); b3 = new JButton("Button #3"); p.add(b3); CardLayout 예제 b1.setbounds(20, 5, 95, 30); b2.setbounds(55, 45, 105, 70); b3.setbounds(180, 15, 105, 90); add(p); setvisible(true); public class AbsoluteTest { public static void main(string args[]) { MyFrame f=new MyFrame();

Q & A