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

Similar documents
9장.key

10장.key

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

11장.key

PowerPoint Presentation

<4D F736F F F696E74202D20C1A63233C0E520B1D7B7A1C7C820C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

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

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

<4D F736F F F696E74202D20C1A63138C0E520C0CCBAA5C6AE20C3B3B8AE28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

<4D F736F F F696E74202D20C1A63139C0E520B9E8C4A120B0FCB8AEC0DA28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

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

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

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

Microsoft PowerPoint - 04-UDP Programming.ppt

PowerPoint 프레젠테이션

PowerPoint Presentation

<4D F736F F F696E74202D20C1A63230C0E520BDBAC0AE20C4C4C6F7B3CDC6AE203128B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

자바로

Microsoft PowerPoint - 14주차 강의자료

Microsoft PowerPoint - 06-Chapter09-Event.ppt

PowerPoint Presentation

8장.그래픽 프로그래밍

Chap12

Microsoft PowerPoint - Java-03.pptx

강의자료

PowerPoint 프레젠테이션

No Slide Title

11-GUI.key

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

05-class.key

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

Microsoft PowerPoint - lec04_05.ppt [호환 모드]

<4D F736F F F696E74202D20C1A63236C0E520BED6C7C3B8B428B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

ch09

PowerPoint 프레젠테이션

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

PowerPoint 프레젠테이션

Java Programing Environment

PowerPoint 프레젠테이션

10-Java Applet

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D3130C0E5C0CCBAA5C6AEC3B3B8AE>

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

슬라이드 1

PowerPoint 프레젠테이션

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

슬라이드 1

PowerPoint 프레젠테이션

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

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

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

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

JMF3_심빈구.PDF

Cluster management software

PowerPoint 프레젠테이션

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

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

운동시뮬레이션 강의 소개

그래픽 chapter.1 스윙컴포넌트그리기 컴포넌트는자신의모양을스스로그린다 X-window, MFC, C# GUI, Android 등 GUI 플랫폼에서 GUI 컴포넌트는스스로자신의모양을그린다. 자바의스윙도예외는아니다. JButton은버튼모양을그리는코드를내장하고, JCo

PowerPoint Presentation

오버라이딩 (Overriding)

PowerPoint Presentation

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

Microsoft PowerPoint - 10장

Cluster management software

PowerPoint Presentation

09-interface.key

PowerPoint Presentation

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

07 자바의 다양한 클래스.key

Microsoft PowerPoint - 12장

PowerPoint 프레젠테이션

비긴쿡-자바 00앞부속

01-OOPConcepts(2).PDF

02 C h a p t e r Java

rmi_박준용_final.PDF

PowerPoint 프레젠테이션

Microsoft PowerPoint - lec09_12.ppt [호환 모드]

PowerPoint 프레젠테이션

슬라이드 1

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

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

Java Coding Standard

제1장 자바 언어 소개

歯NetworkKawuiBawuiBo.PDF

5장.key

중간고사


자바 프로그래밍

No Slide Title

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

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

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

* Factory class for query and DML clause creation * tiwe * */ public class JPAQueryFactory implements JPQLQueryFactory private f

FileMaker ODBC and JDBC Guide

쉽게 풀어쓴 C 프로그래밍

연습문제이론홀수정답

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

신림프로그래머_클린코드.key

제13강. 스윙(Swing)

PowerPoint 프레젠테이션

Transcription:

[ 10 ]

..,..,,,., 2

1. 3

Section 1 p408 (event) (listen) (event listener) 4

Section 1 [ 1: ] [ 2: ] 5

Section 1 (ActionEvent) (MouseEvent) 6

Section 1 EventObject getsource() 7

Section 1 8

Section 1 MouseListener 9

Section 1 java.awt.event EventListener 10

Section 1 11

2. 12

Section 2 p416 [ 1: ] ActionListener [ 2: ].addactionlistener( ) 13

ButtonActionWin Section 2 ActionListener actionperformed( ) btnok, btncancel addactionlistener( ) 14

10-1 Section 2 import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jbutton; import javax.swing.jlabel; import java.awt.borderlayout; import java.awt.gridlayout; public class ButtonActionWin extends JFrame implements ActionListener { private static final long serialversionuid = 1L; JButton btnok = new JButton("OK"); JButton btncancel = new JButton("Cancel"); JLabel dlb = new JLabel("."); public ButtonActionWin() { setdefaultcloseoperation(jframe.exit_on_close); setsize(300, 130); } // makebuttonandeventhandle(); setvisible(true); public void makebuttonandeventhandle() { JPanel p = new JPanel(new GridLayout(0, 2)); p.add(btnok); p.add(btncancel); add(p, BorderLayout.CENTER); add(dlb, BorderLayout.SOUTH); } //2 btnok.addactionlistener(this); btncancel.addactionlistener(this); public void actionperformed(actionevent evt) { // String strcmd = evt.getactioncommand(); } // if (strcmd.equals("ok")) { dlb.settext(" OK Button"); } else if (strcmd.equals("cancel")) { dlb.settext(" Cancel Button"); } public static void main(string[] args) { ButtonActionWin mywin = new ButtonActionWin(); mywin.settitle(" "); } } 15

Section 2 (press) (release) 16

10-2 Section 2 import java.awt.*; import java.awt.event.*; import javax.swing.jframe; public class MouseEventWin extends JFrame { private static final long serialversionuid = 1L; MouseEventWin childwin = null; static int countchild; public MouseEventWin() { setdefaultcloseoperation(jframe.exit_on_close); setsize(400, 150); setvisible(true); //register mouse event handler, motion event handler addmouselistener(new MyMouseListener()); } class MyMouseListener implements MouseListener { public void mousepressed(mouseevent e) { Rectangle bounds = getbounds(); int x = e.getx() + bounds.x; int y = e.gety() + bounds.y; 17

MouseListenr MouseEvent MouseListenr MouseEvent Section 2 18

MouseMotionListener Section 2 (move) (drag) MouseListener, MouseMotionListener 7 MouseInputListener 19

s1, s2, s3 Pressed/Released Entered/Exited/ Clicked Dragged/Moved Section 2 20

7 MyMouseListener Section 2 MouseListener 5 MouseMotionListener 2 21

4 4 [ 1: ] [ 2: ] [ 3: ] [ 4: ] Section 2 22

Section 2 4 ActionEvent 23

Section 2 24

Section 2 25

3. 26

Section 3 p432 MouseListener MouseMotionListener 5 2 7 3 27

Section 3 28

Section 3 MouseAdapter MouseMotionAdapter mousemoved() 29

4. 30

Section 4 p110,,, JMenuItem JCheckBoxMenuItem ComponentEvent ComponentEvent getcomponent() 31

10-5 Section 4 import java.awt.event.componentadapter; import java.awt.event.componentevent; import javax.swing.jframe; import javax.swing.jtextarea; public class ComponentEventWin extends JFrame { private static final long serialversionuid = 1L; JTextArea txtarea = new JTextArea(); class MyComponentAdapter extends ComponentAdapter { public void componentresized(componentevent evt) { String str = evt.getsource().getclass() + " : "; str += evt.getcomponent().getbounds() + "\n"; txtarea.append(str); } } public ComponentEventWin() { setdefaultcloseoperation(jframe.exit_on_close); setsize(600, 150); add(txtarea, "Center"); txtarea.addcomponentlistener(new MyComponentAdapter()); setvisible(true); } public static void main(string[] args) { ComponentEventWin mywin = new ComponentEventWin(); mywin.settitle(" "); } } 32

Section 4 ItemEvent ItemEvent JCheckBox, JList, JComboBox, JCheckBox, MenuItem ItemEvent ItemSelectable on/off selected/deselected ItemListener ItemEvent 33

JCheckBoxMenuItem JMenu JCheckBoxMenuItem mainmenu.add(submenu) JCheckBoxMenuItem Section 4 / additemlistener( ) itemstatechanged() 34

Section 4 10-6 JCheckBox JCheckBoxMenuItem ItemEvent JCheckBoxMenuItem JCheckBox JList JLable ItemEvent 35

10-6 import java.awt.event.itemevent; import java.awt.event.itemlistener; import javax.swing.abstractbutton; import javax.swing.jcheckbox; import javax.swing.jcheckboxmenuitem; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jpanel; import javax.swing.jtextarea; public class ItemEventWin extends JFrame implements ItemListener { private static final long serialversionuid = 1L; JPanel pcheck = new JPanel(); // JTextArea txtarea = new JTextArea(); JLabel status = new JLabel(" "); public ItemEventWin() { setdefaultcloseoperation(jframe.exit_on_close); setsize(300, 200); } makecheckbox(); makemenuandeventhandle(); add(pcheck, "North"); add(txtarea, "Center"); add(status, "South"); setvisible(true); public void makecheckbox() { JCheckBox box1 = new JCheckBox(" "); JCheckBox box2 = new JCheckBox(" "); JCheckBox box3 = new JCheckBox(" "); JCheckBox box4 = new JCheckBox(" "); box1.additemlistener(this); box2.additemlistener(this); 36 } Section 4 box3.additemlistener(this); box4.additemlistener(this); pcheck.add(box1); pcheck.add(box2); pcheck.add(box3); pcheck.add(box4); } public void makemenuandeventhandle() { JMenuBar mbar = new JMenuBar(); JMenu mainmenu = new JMenu(" "); JMenu submenu = new JMenu(" "); JCheckBoxMenuItem subcheck1 = new JCheckBoxMenuItem(" "); JCheckBoxMenuItem subcheck2 = new JCheckBoxMenuItem(" "); submenu.add(subcheck1); submenu.add(subcheck2); subcheck1.additemlistener(this); subcheck2.additemlistener(this); } mainmenu.add(submenu); mbar.add(mainmenu); setjmenubar(mbar); public void itemstatechanged(itemevent evt) { String str = ((AbstractButton) evt.getitem()).gettext(); if (evt.getstatechange() == ItemEvent.DESELECTED) str += " \n"; else str += " \n"; status.settext(str); txtarea.append(str); } public static void main(string[] args) { ItemEventWin mywin = new ItemEventWin(); mywin.settitle(" "); }

Section 4 Container, JDialog, JFrame, JPanel, Jwindow ContainerListener ContainerListener ContainerEvent 37

Section 4,, Vector, [Add button] [Remove button] [Add button] [Remove button] 38

10-7 import java.awt.borderlayout; import java.awt.gridlayout; Section 4 import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.event.containerevent; import java.awt.event.containerlistener; import javax.swing.*; import java.util.vector; public class ContainerEventWin extends JFrame implements ContainerListener, ActionListener { private static final long serialversionuid = 1L; JButton btnadd = new JButton("Add button"); JButton btnremove = new JButton("Remove button"); JLabel lbl = new JLabel(); JPanel p1 = new JPanel(); JButton recentbtn; // int btncount = 0; Vector<JButton> arybtn = new Vector<JButton>(); public ContainerEventWin() { JPanel p2 = new JPanel(new GridLayout(0, 2)); p2.add(btnadd); p2.add(btnremove); add(lbl, BorderLayout.NORTH); add(p1, BorderLayout.CENTER); add(p2, BorderLayout.SOUTH); // p1.addcontainerlistener(this); // btnadd.addactionlistener(this); btnremove.addactionlistener(this); } setsize(300, 200); setvisible(true); //ActionListener's method implementation 39

Section 4 Component FocusListener FocusAdapter FocusListener 40

Section 4 10-8 import java.awt.event.focusevent; import java.awt.event.focuslistener; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jtextarea; public class FocusEventWin extends JFrame implements FocusListener { private static final long serialversionuid = 1L; JTextArea txtarea = new JTextArea(); public FocusEventWin() { setdefaultcloseoperation(jframe.exit_on_close); setsize(350, 150); // makewindowandeventhandle(); setvisible(true); } public void makewindowandeventhandle() { JButton btn = new JButton(" "); add(txtarea, "Center"); add(btn, "South"); // 41

5. 42

Section 5 p448 (Graphics Context) 43

Section 5 Graphics Graphics,,, paint() update() paintcomponent() 44

Section 5 Color (graphics context) (foreground) Graphics setcolor() Component setbackground() setforeground() Color (background) RGB 45

Section 5 10-9 paint() Graphics g setcolor() drawstring(, x, y) package graphics; import java.awt.color; import java.awt.dimension; import java.awt.graphics; import javax.swing.jframe; public class DrawStringWin extends JFrame { private static final long serialversionuid = 1L; public DrawStringWin() { setdefaultcloseoperation(jframe.exit_on_close); setsize(300, 150); setvisible(true); } public 10 void paint(graphics g) { 46

Section 5 drawroundrect() arcwidth argheight drawrect(), fillroundrect() 47

Section 5 10-10 13 4 13 switch-case, 48

10-10 Section 5 package graphics; import java.awt.color; import java.awt.container; import java.awt.dimension; import java.awt.graphics; import javax.swing.jframe; public class DrawLineWin extends JFrame { private static final long serialversionuid = 1L; public DrawLineWin() { setdefaultcloseoperation(jframe.exit_on_close); } setsize(400, 200); setvisible(true); public void paint(graphics g) { //get ContentPane Container win = getcontentpane(); // Dimension d = win.getsize(); int clientwidth = d.width; // int clientheight = d.height;// int incheight = (clientheight-10) / 12; for (int i = 0; i < 13; i++) { switch (i) { case 0: g.setcolor(color.black); break; case 1: g.setcolor(color.blue); break; case 2: g.setcolor(color.cyan); break; 10 case 3: g.setcolor(color.darkgray); 49

, Section 5 drawoval() drawarc() drawpolygon() fillpolygon() 50

Section 5 10-11 filloval() Color Runnable run() JFrame 51

10-11 Section 5 package graphics; import java.awt.color; import java.awt.dimension; import java.awt.graphics; import javax.swing.jframe; public class DrawOvalWin extends JFrame implements Runnable { private static final long serialversionuid = 1L; public DrawOvalWin() { setdefaultcloseoperation(jframe.exit_on_close); new Thread(this).start(); } setsize(400, 200); setvisible(true); public void run() { while(true) { repaint(); try { Thread.sleep(200); } catch(exception e) { System.out.println(e); } } } 52

6. 53

Section 6 p460 drawbytes(), drawchars(), drawstring() (x, y) 54

Section 6 Font setfont() 55

Section 6 FontMetrics 56

Section 6 FontMetrics strwidth 57

10-12 Section 6 58

10-12 Section 6 package graphics; import java.awt.color; import java.awt.dimension; import java.awt.font; import java.awt.fontmetrics; import java.awt.graphics; import java.awt.graphicsenvironment; import javax.swing.jframe; import javax.swing.jpanel; public class FontWin extends JFrame { private static final long serialversionuid = 1L; Color[] manycolors = { Color.black, Color.blue, Color.cyan, Color.gray, Color.green, Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.yellow, Color.darkGray }; int[] styles = { Font.PLAIN, Font.ITALIC, Font.BOLD, Font.BOLD Font.ITALIC }; String[] stylenames = { "plain", "bold", "italic", "bold/ italic" }; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontnames = ge.getavailablefontfamilynames(); public FontWin() { setdefaultcloseoperation(jframe.exit_on_close); add(new MyPanel()); } setsize(400, 200); setvisible(true); private int random(int r) { return (int) Math.floor(Math.random() * r); } class MyPanel extends JPanel { private static final long serialversionuid = 1L; 59

Section 6 ImageIcon ImageIcon JLabel 60

Section 6 10-13 package graphics; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; public class ImageWin extends JFrame { private static final long serialversionuid = 1L; public ImageWin() { setdefaultcloseoperation(jframe.exit_on_close); ImageIcon img = new ImageIcon("image.png", " "); JLabel lb = new JLabel(img); add(lb); Integer height = new Integer(img.getIconHeight()); Integer width = new Integer(img.getIconWidth()); JLabel size = new JLabel(img.getDescription() + ": " + height + " " + width); add(size, "South"); setsize(400, 200); setvisible(true); } 10 61

Section 6 Graphics drawimage() drawimage(img, x, y, imgwidth, imgheight, this) Image img (x, y) Container getinsets() Insets in = getinsets(); Insets top, left, right, bottom 62

10-14 Section 6 package graphics; import java.awt.graphics; import java.awt.image; import java.awt.insets; import javax.swing.imageicon; import javax.swing.jframe; public class DrawImageWin extends JFrame { private static final long serialversionuid = 1L; Image img; Insets in; public DrawImageWin() { setdefaultcloseoperation(jframe.exit_on_close); ImageIcon imgico = new ImageIcon("image.png"); img = imgico.getimage(); setsize(350, 250); setvisible(true); in = getinsets(); System.out.println(in.top + " " + in.bottom + " " + in.left + " " + in.right); } public void paint(graphics g) { 10 //int origwidth = img.getwidth(this); 63

64

[ Add your company slogan ] Thank You!