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

Similar documents
10장.key

9장.key

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

11장.key

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint Presentation

<4D F736F F F696E74202D20C1A63138C0E520C0CCBAA5C6AE20C3B3B8AE28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

PowerPoint 프레젠테이션

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D3130C0E5C0CCBAA5C6AEC3B3B8AE>

<4D F736F F F696E74202D20C1A63139C0E520B9E8C4A120B0FCB8AEC0DA28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

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

PowerPoint Presentation

PowerPoint Presentation

Microsoft PowerPoint - 14주차 강의자료

No Slide Title

<4D F736F F F696E74202D20C1A63230C0E520BDBAC0AE20C4C4C6F7B3CDC6AE203128B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

오버라이딩 (Overriding)

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

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

<4D F736F F F696E74202D20C1A63233C0E520B1D7B7A1C7C820C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

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

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

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Microsoft PowerPoint - Java-03.pptx

강의자료

Microsoft PowerPoint - 10장

Cluster management software

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

Cluster management software

Microsoft PowerPoint - 04-UDP Programming.ppt

PowerPoint 프레젠테이션

자바로

PowerPoint 프레젠테이션

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

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

PowerPoint 프레젠테이션

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

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

PowerPoint 프레젠테이션

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

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

11-GUI.key

No Slide Title

슬라이드 1

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

Java Programing Environment

PowerPoint 프레젠테이션

<4D F736F F F696E74202D20C1A63236C0E520BED6C7C3B8B428B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

슬라이드 1

Microsoft PowerPoint - 06-Chapter09-Event.ppt

연습문제이론홀수정답

8장.그래픽 프로그래밍

비긴쿡-자바 00앞부속

PowerPoint 프레젠테이션

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

슬라이드 1

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

Chap12

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

05-class.key

rmi_박준용_final.PDF

JMF3_심빈구.PDF

Microsoft PowerPoint - Java7.pptx

PowerPoint 프레젠테이션

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

Microsoft PowerPoint - 12장

5장.key

PowerPoint Presentation

iii. Design Tab 을 Click 하여 WindowBuilder 가자동으로생성한 GUI 프로그래밍환경을확인한다.

PowerPoint Presentation

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

C프로-3장c03逞풚

PowerPoint Presentation

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

ch09

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

PowerPoint Presentation

중간고사

09-interface.key

PowerPoint Presentation

Design Issues

PowerPoint Presentation

Java ...

12-file.key

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

쉽게 풀어쓴 C 프로그래밍

歯NetworkKawuiBawuiBo.PDF

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

02 C h a p t e r Java

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

13ÀåÃß°¡ºÐ

<4D F736F F F696E74202D20C1A63034B0AD202D20C7C1B7B9C0D3B8AEBDBAB3CABFCD20B9ABB9F6C6DBC0D4B7C2>

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

PowerPoint Presentation

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

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

Cluster management software

K&R2 Reference Manual 번역본

Transcription:

8 장 1 번 public class MyFrame extends JFrame { public MyFrame(String title) { super(title); this. setsize(400,200); new MyFrame("Let's study Java"); 2번 public class MyBorderLayoutFrame extends JFrame { public MyBorderLayoutFrame() { super("borderlayout Practice"); this. c.setlayout(new BorderLayout(5, 7)); c.add(new JButton("East"), BorderLayout.EAST); c.add(new JButton("West"), BorderLayout.WEST); c.add(new JButton("North"), BorderLayout.NORTH); c.add(new JButton("South"), BorderLayout.SOUTH); c.add(new JButton("Center"), BorderLayout.CENTER); setsize(400,200); new MyBorderLayoutFrame(); 3번

public class FlowLayoutPractice extends JFrame { public FlowLayoutPractice() { super("flowlayout Practice"); this. Container contentpane = getcontentpane(); contentpane.setlayout(new FlowLayout()); contentpane.add(new JLabel("100")); contentpane.add(new JLabel("+")); contentpane.add(new JLabel("200")); contentpane.add(new JButton("=")); contentpane.add(new JLabel("300")); setsize(400,100); new FlowLayoutPractice(); 4번 public class TenColorButtonFrame extends JFrame { public TenColorButtonFrame() { super("ten Color Buttons Frame"); this. Container contentpane = getcontentpane(); contentpane.setlayout(new GridLayout(1, 10)); Color [] color = {Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.GRAY, Color.PINK, Color.LIGHT_GRAY; for(int i=0; i<10; i++) { JButton button = new JButton(Integer.toString(i)); button.setopaque(true); // 배경색이보이게함

button.setbackground(color[i]); // 각버튼의색설정 contentpane.add(button); // 컨텐트팬에버튼부착 setsize(500,200); new TenColorButtonFrame(); 5번 public class Plate4x4Frame extends JFrame { public Plate4x4Frame() { super("4x4 Color Frame"); this. c.setlayout(new GridLayout(4, 4)); JLabel [] label = new JLabel [16]; Color [] color = {Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.GRAY, Color.PINK, Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY, Color.BLACK, Color.ORANGE, Color.BLUE,Color.MAGENTA; for(int i=0; i<label.length; i++) { label[i] = new JLabel(Integer.toString(i)); label[i].setopaque(true); label[i].setbackground(color[i]); c.add(label[i]); setsize(500,200); new Plate4x4Frame();

6번 public class RandomLabelFrame extends JFrame { public RandomLabelFrame() { super("random Labels"); this. c.setlayout(null); for(int i=0; i<20; i++) { JLabel label = new JLabel(Integer.toString(i)); label.settext(""); // 문자열없도록초기화 label.setopaque(true); label.setbackground(color.blue); int x = (int)(math.random()*200) + 50; int y = (int)(math.random()*200) + 50; label.setlocation(x,y); label.setsize(10,10); c.add(label); setsize(300,300); new RandomLabelFrame();

9장 1번 public class MouseEventFrame extends JFrame { public MouseEventFrame() { super(" 마우스올리기내리기연습 "); c.setlayout(new FlowLayout()); JLabel label = new JLabel(" 자기야 "); label.addmouselistener(new MouseAdapter() { public void mouseentered(mouseevent e) { la.settext(" 사랑해 "); public void mouseexited(mouseevent e) { la.settext(" 자기야 "); ); c.add(label); static public void main(string [] args) { new MouseEventFrame();... public class MouseEventFrame extends JFrame { public MouseEventFrame() {

super(" 마우스올리기내리기연습 "); c.setlayout(new FlowLayout()); JLabel label = new JLabel(" 자기야 "); label.addmouselistener(new MouseAdapter() { public void mouseentered(mouseevent e) { la.settext(" 사랑해 "); public void mouseexited(mouseevent e) { la.settext(" 자기야 "); ); c.add(label); static public void main(string [] args) { new MouseEventFrame(); 2번 public class KeyEventFrame extends JFrame { KeyEventFrame() { super(" 키누르기떼기연습 "); c.setbackground(color.red); c.addkeylistener(new KeyAdapter() { public void keypressed(keyevent e) {

); if(e.getkeychar() == 'R') { getcontentpane().setbackground(color.red); public void keyreleased(keyevent e) { if(e.getkeychar() == 'R') { getcontentpane().setbackground(color.cyan); c.requestfocus(); new KeyEventFrame(); 3번 public class MouseDraggingFrame extends JFrame { public MouseDraggingFrame() { super(" 드래깅동안 YELLOW로변경 "); c.setbackground(color.green); MyMouseListener ml = new MyMouseListener(); c.addmousemotionlistener(ml); c.addmouselistener(ml);

class MyMouseListener extends MouseAdapter implements MouseMotionListener { public void mousedragged(mouseevent e) { Container c = (Container)e.getSource(); c.setbackground(color.yellow); public void mousemoved(mouseevent e) { public void mousereleased(mouseevent e) { Container c = (Container)e.getSource(); c.setbackground(color.green); static public void main(string [] args) { new MouseDraggingFrame(); 4번 public class KeyPlusMinusFrame extends JFrame { public KeyPlusMinusFrame() { super("+,- 키로폰트크기조절 "); c.setlayout(new FlowLayout()); JLabel label = new JLabel("Love Java"); label.setfont(new Font("TimesRoman", Font.PLAIN, 10)); // 10 픽셀크기 label.addkeylistener(new KeyAdapter() { public void keypressed(keyevent e) { if(e.getkeychar() == '+') { Font f = la.getfont(); int size = f.getsize(); la.setfont(new Font("TimesRoman", Font.PLAIN, size+5));

else if(e.getkeychar() == '-') { Font f = la.getfont(); int size = f.getsize(); if(size <= 5) return; la.setfont(new Font("TimesRoman", Font.PLAIN, size-5)); ); c.add(label); label.requestfocus(); static public void main(string [] args) { new KeyPlusMinusFrame(); 5번 public class ClickPracticeFrame extends JFrame { public ClickPracticeFrame() { super(" 클릭연습 "); c.setlayout(null); JLabel label = new JLabel("C"); label.setlocation(50,50); label.setsize(20, 20);

label.addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent e) { Container c = la.getparent(); int xbound = c.getwidth() - la.getwidth(); // 레이블의폭만큼감소 int ybound = c.getheight() - la.getheight(); // 레이블의높이만큼감소 int x = (int)(math.random()*xbound); int y = (int)(math.random()*ybound); la.setlocation(x, y); ); c.add(label); static public void main(string [] args) { new ClickPracticeFrame(); 6번 public class FrameResize extends JFrame { FrameResize() { super(" 키로프레임크기조절 "); Container contentpane = getcontentpane(); // 컨텐트팬알아내기 contentpane.setlayout(new FlowLayout()); // 배치관리자 contentpane.add(new JButton("A")); // 더미버튼추가 contentpane.addkeylistener(new MyKeyListener()); // 키리스너달기 setsize(150, 150); contentpane.requestfocus(); // 컨텐트팬에포커스설정. 키입력가능해짐 class MyKeyListener extends KeyAdapter { // 키리스너

public void keypressed(keyevent e) { int w = getwidth(); // JFrame 윈도우의너비 int h = getheight(); // JFrame 윈도우의높이 switch (e.getkeycode()) { // 입력된키문자 case KeyEvent.VK_F1: setsize(w + 10, h + 10); // JFrame 10픽셀증가 break; case KeyEvent.VK_F2: setsize(w - 10, h - 10); // JFrame 10픽셀축소 break; case KeyEvent.VK_Q : System.exit(0); // 프로그램종료 new FrameResize(); 7번 public class ButtoActionFrame extends JFrame { String text [] = {"+2", "-1", "%4"; JLabel la = new JLabel(); JButton btn [] = new JButton [text.length]; ButtoActionFrame() { super("0으로만들기 "); // 정수레이블생성 int num= (int)(math.random()*60 + 1); // 1에서 60 사이의임의의정수 la.settext(integer.tostring(num)); // 정수를문자열로만들어레이블에출력 la.setfont(new Font("Gothic", Font.ITALIC, 20)); JPanel p = new JPanel(); c.add(p, BorderLayout.CENTER);

p.add(la); JPanel q = new JPanel(); c.add(q, BorderLayout.SOUTH); // 3 개의버튼생성 MyActionListener listener = new MyActionListener(); // Action 리스너객체생성 for(int i=0; i<text.length; i++) { btn[i] = new JButton(text[i]); btn[i].addactionlistener(listener); // 리스너달기 q.add(btn[i]); // 컨텐트팬에버튼달기 class MyActionListener implements ActionListener { public void actionperformed(actionevent e) { ButtoActionFrame.this.setTitle("0 으로만들기 "); // 타이틀바초기화 int n = Integer.parseInt(la.getText()); // 현재정수를알아냄 switch(e.getactioncommand()) { case "+2": n += 2; // 2 증가 btn[0].setenabled(false); // 버튼비활성화시켜다시클릭되지않게함 break; case "-1": n--; // 1 증가 btn[1].setenabled(false); // 버튼비활성화시켜다시클릭되지않게함 break; case "%4": n %= 4; // 4로나눈나머지계산 btn[2].setenabled(false); // 버튼비활성화시켜다시클릭되지않게함 break; la.settext(integer.tostring(n)); // 정수를문자열로만들어레이블에출력 if(n == 0) { ButtoActionFrame.this.setTitle(" 성공 "); for(int i=0; i<text.length; i++) { btn[i].setenabled(true);

else { int num= (int)(math.random()*60 + 1); // 1에서 60 사이의임의의정수 la.settext(integer.tostring(num)); // 정수를문자열로만들어레이블에출력 if(btn[0].isenabled() == false && btn[1].isenabled() == false && btn[2].isenabled() == false) settitle(" 실패 "); new ButtoActionFrame();