10장.key

Similar documents
PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D3130C0E5C0CCBAA5C6AEC3B3B8AE>

PowerPoint 프레젠테이션

Microsoft PowerPoint - 10장

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

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

<4D F736F F F696E74202D20C1A63138C0E520C0CCBAA5C6AE20C3B3B8AE28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

11장.key

9장.key

Microsoft PowerPoint - 14주차 강의자료

PowerPoint Presentation

Microsoft PowerPoint - 06-Chapter09-Event.ppt

Cluster management software

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

자바로

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

오버라이딩 (Overriding)

Microsoft PowerPoint - Java-03.pptx

<4D F736F F F696E74202D20C1A63139C0E520B9E8C4A120B0FCB8AEC0DA28B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

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

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

Microsoft PowerPoint - 04-UDP Programming.ppt

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

PowerPoint Presentation

강의자료

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

연습문제이론홀수정답

Java Programing Environment

PowerPoint 프레젠테이션

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

<4D F736F F F696E74202D20C1A63233C0E520B1D7B7A1C7C820C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

PowerPoint 프레젠테이션

No Slide Title

<4D F736F F F696E74202D20C1A63230C0E520BDBAC0AE20C4C4C6F7B3CDC6AE203128B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

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

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

슬라이드 1

<4D F736F F F696E74202D20C1A63236C0E520BED6C7C3B8B428B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

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

슬라이드 1

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

PowerPoint 프레젠테이션

슬라이드 1

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

02 C h a p t e r Java

05-class.key

Chap12

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint Presentation

ch09

PowerPoint 프레젠테이션

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

rmi_박준용_final.PDF

슬라이드 1

09-interface.key

슬라이드 1

중간고사

JMF3_심빈구.PDF

PowerPoint Presentation

비긴쿡-자바 00앞부속

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

PowerPoint 프레젠테이션

Microsoft PowerPoint - Java7.pptx

11-GUI.key

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

운동시뮬레이션 강의 소개

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

자바 쓰레드 능숙하게 다루기

01-OOPConcepts(2).PDF

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

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

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

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

歯NetworkKawuiBawuiBo.PDF

<335FC0DAB9D92E687770>

5장.key

슬라이드 1

쉽게 풀어쓴 C 프로그래밍

PowerPoint Presentation

자바 프로그래밍

PowerPoint Presentation

PowerPoint Presentation

제13강. 스윙(Swing)

10-Java Applet

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

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

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

JAVA PROGRAMMING 실습 08.다형성

Spring Boot/JDBC JdbcTemplate/CRUD 예제

Java

12-file.key

1

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

13ÀåÃß°¡ºÐ

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

PowerPoint Presentation

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

Transcription:

JAVA Programming 1

2 (Event Driven Programming)! :,,,! ( )! : (batch programming)!! ( : )!!!!

3 (Mouse Event, Action Event) (Mouse Event, Action Event) (Mouse Event, Container Event) (Key Event) (Key Event, Action Event)

4 GUI

5! GUI! ),,,,!!!,!

6

7?!,!

8!!!!!!!!!, ActionEvent : MouseEvent :,, ItemEvent :! Object EventObject.getSource() Object

9

10

(Event Listener) 11?!, JDK (interface)!! ) ActionListener interface ActionListener { // public void actionperformed(actionevent e); // Action! ) MouseListener interface MouseListener { // 5 public void mousepressed(mouseevent e); // public void mousereleased(mouseevent e); // public void mouseclicked(mouseevent e); // public void mouseentered(mouseevent e); // public void mouseexited(mouseevent e); //

12

Tip : addxxxlistener? 13!. JButton.addActionListener(); // Action JButton.addKeyListener(); // Key JButton.addFocusListener(); // Focus!. JButton.addActionListener(new MyButtonListener1()); JButton.addActionListener(new MyButtonListener2()); JButton.addActionListener(new MyButtonListener3());,.

14 3 1. 2. (inner class) 3. (anonymous class)

10-1 : Action import javax.swing.*; import java.awt.event.*; import java.awt.*; 15 MyActionListener.java public class IndepClassListener extends JFrame { public IndepClassListener() { settitle( Action ); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.setlayout(new FlowLayout()); Jbutton btn = new Jbutton( Action ); btn.addactionlistener(new MyActionListener()); // Action c.add(btn); setsize(350, 150); setvisible(true); public static void main(string [] args) { new IndepClassListener(); class MyActionListener implements ActionListener { public void actionperformed(actionevent e) { JButton b = (JButton)e.getSource(); if(b.gettext().equals("action")) b.settext(""); else b.settext("action");

10-2 : Action import javax.swing.*; import java.awt.event.*; import java.awt.*; public class InnerClassListener extends JFrame { InnerClassListener() { settitle("action "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.setlayout(new FlowLayout()); JButton btn = new JButton("Action"); btn.addactionlistener(new MyActionListener()); c.add(btn); 16 Action private InnerClassListener InnerClassListener setsize(350, 150); setvisible(true); private class MyActionListener implements ActionListener { private public class void actionperformed(actionevent MyActionListener implements e) { ActionListener { public JButton void b actionperformed(actionevent = (JButton)e.getSource(); e) { JButton if(b.gettext().equals("action")) b = (JButton)e.getSource(); if(b.gettext().equals("action")) b.settext(""); else b.settext(""); elseb.settext("action"); // InnerClassListener b.settext("action"); JFrame // InnerClassListener.this.setTitle(b.getText()); InnerClassListener JFrame // InnerClassListener.this.setTitle(b.getText()); //.. public static void main(string [] args) { new InnerClassListener();

17?! ( + ) new ( ) {...... ;! ActionListener

10-3 : Action import java.awt.*; import java.awt.event.*; import javax.swing.*; public class AnonymousClassListener extends JFrame { public AnonymousClassListener() { settitle("action "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.setlayout(new FlowLayout()); JButton btn = new JButton("Action"); c.add(btn); Action AnonymousClassListener JFrame btn.addactionlistener(new ActionListener() { btn.addactionlistener(new public void actionperformed(actionevent ActionListener() e) { { public JButton void b = actionperformed(actionevent (JButton)e.getSource(); e) { if(b.gettext().equals("action")) JButton b = (JButton)e.getSource(); if(b.gettext().equals("action")) b.settext(""); else b.settext(""); else b.settext("action"); settitle(b.gettext()); b.settext("action"); settitle(b.gettext()); ); ); setsize(350, 150); setvisible(true); public static void main(string [] args) { new AnonymousClassListener(); 18

10-4 : 19 "hello".

10-4 20 import javax.swing.*; import java.awt.event.*; import java.awt.*; public class MouseListenerEx extends JFrame { private JLabel la = new JLabel("Hello"); public MouseListenerEx() { settitle("mouse "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.addmouselistener(new MyMouseListener()); c.setlayout(null); la.setsize(50, 20); la.setlocation(30, 30); c.add(la); la("hello" ). class MyMouseListener implements MouseListener { public void mousepressed(mouseevent e) { int x = e.getx(); int y = e.gety(); la.setlocation(x, y); public void mousereleased(mouseevent e) { public void mouseclicked(mouseevent e) { public void mouseentered(mouseevent e) { public void mouseexited(mouseevent e) { public static void main(string [] args) { new MouseListenerEx(); setsize(250, 250); setvisible(true);

(Adapter) 21! (mousepressed()) 4! MouseAdapter class MouseAdapter implements MouseListener, MouseMotionListener, MouseWheelListener { public void mousepressed(mouseevent e) { public void mousereleased(mouseevent e) { public void mouseclicked(mouseevent e) { public void mouseentered(mouseevent e) { public void mouseexited(mouseevent e) { public void mousedragged(mouseevent e) { public void mousemoved(mouseevent e) { public void mousewheelmoved(mousewheelevent e) {! ActionAdapter, ItemAdapter

22 JDK

(MouseAdapter) 23 JLabel la; contentpane.addmouselistener(new MyMouseListener());.. class MyMouseListener implements MouseListener { public void mousepressed(mouseevent e) { int x = e.getx(); int y = e.gety(); la.setlocation(x, y); public void mousereleased(mouseevent e) { public void mouseclicked(mouseevent e) { public void mouseentered(mouseevent e) { public void mouseexited(mouseevent e) { JLabel la; contentpane.addmouselistener(new MyMouseAdapter());.. class MyMouseAdapter extends MouseAdapter { public void mousepressed(mouseevent e) { int x = e.getx(); int y = e.gety(); la.setlocation(x, y); MouseAdapter MouseListener

10-5 : MouseAdapter 24 MouseAdapter 10-4. import java.awt.*; import java.awt.event.*; import javax.swing.*;] public class MouseAdapterEx extends JFrame { private JLabel la = new JLabel("Hello"); public MouseAdapterEx() { settitle("mouse "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.addmouselistener(new MyMouseAdapter()); class MyMouseAdapter extends MouseAdapter { public void mousepressed(mouseevent e) { int x = e.getx(); int y = e.gety(); la.setlocation(x, y); public static void main(string [] args) { new MouseAdapterEx(); c.setlayout(null); la.setsize(50, 20); la.setlocation(30, 30); c.add(la); setsize(250, 250); setvisible(true);

Key 25, Key!!! (Unicode )!, (focus) (focus)!! : 2 component.setfocusable(true); // component component.requestfocus(); // componen component.setfocusable(true);

26! JFrame setvisible(true) setvisible(true); // component.setfocusable(true); component.requestfocus();! component.addmouselistener(new MouseAdapter() { public void mouseclicked(mouseevent e) { Component c = (Component)e.getSource(); // c.setfocusable(true); c.requestfocus(); ); // 10-8

KeyListener 27 KeyListener 3 ❶ (KeyListener) void keypressed(keyevent e) { //, Unicode ❸ ❷ void keyreleased(keyevent e) { // void keytyped(keyevent e) { // KeyListener ❶ ❷ ❸ component.addkeylistener(mykeylistener);

2 28 1.!! A~Z, a~z, 0~9,!, @, &! keypressed(), keytyped(), keyreleased() 2.! ( ) <Function>, <Home>, <Up>, <Delete>, <Control>, <Shift>, <Alt>!! ( )! keypressed(), keyreleased()!

(Virtual Key) 29 KeyEvent

30 : KeyEvent KeyEvent 1. (), char KeyEvent.getKeyChar()! ()! 2., int KeyEvent.getKeyCode()!! (Virtual Key) KeyEvent 3. String KeyEvent.getKeyText(int keycode)! Static! keycode ( ) F1 "F1", Shift "SHIFT"

31 KeyEvent getkeychar() getkeycode()

10-6 : KeyEvent KeyListener 32 import javax.swing.*; import java.awt.event.*; import java.awt.*; public class KeyListenerEx extends JFrame { private JLabel [] keymessage; setsize(300,150); setvisible(true); c.setfocusable(true); c.requestfocus(); public KeyListenerEx() { settitle("keylistener "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.setlayout(new FlowLayout()); c.addkeylistener(new MyKeyListener()); keymessage = new JLabel [3]; keymessage[0] = new JLabel(" getkeycode() "); keymessage[1] = new JLabel(" getkeychar() "); keymessage[2] = new JLabel(" getkeytext() "); for(int i=0; i<keymessage.length; i++) { c.add(keymessage[i]); keymessage[i].setopaque(true); keymessage[i].setbackground(color.yellow); class MyKeyListener extends KeyAdapter { public void keypressed(keyevent e) { int keycode = e.getkeycode(); char keychar = e.getkeychar(); keymessage[0].settext(integer.tostring(keycode)); keymessage[1].settext(character.tostring(keychar)); keymessage[2].settext(e.getkeytext(keycode)); public static void main(string [] args) { new KeyListenerEx();

33 <Control> w <F1> 9 9 9 <Home> <Home> <Home>

10-7 : <F1>, % 34 import javax.swing.*; import java.awt.event.*; import java.awt.*; public class KeyCodeEx extends JFrame { private JLabel la = new JLabel(); public KeyCodeEx() { settitle("key Code : F1:, % "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.addkeylistener(new MyKeyListener()); c.add(la); class MyKeyListener extends KeyAdapter { public void keypressed(keyevent e) { la.settext(e.getkeytext(e.getkeycode())); if(e.getkeychar() == '%') contentpane.setbackground(color.yellow); else if(e.getkeycode() == KeyEvent.VK_F1) contentpane.setbackground(color.green); public static void main(string [] args) { new KeyCodeEx(); setsize(300,150); setvisible(true); c.setfocusable(true); c.requestfocus(); % e.getkeychar(). F1 e.getkeycode() KeyEvent.VK_F1

10-7 35 <F1> % % Shift+5, 5 5. % 5 if(e.getkeychar() == '%')

10-8 : (UP), (DOWN), (LEFT), (RIGHT) "HELLO" 36,,, "HELLO". "HELLO" JLabel,,, 10.. "HELLO" (50, 50). (50,50),,, 10 "HELLO",,,..

:,,, 37 import javax.swing.*; import java.awt.event.*; import java.awt.*; public class FlyingTextEx extends JFrame { private final int FLYING_UNIT = 10; private JLabel la = new JLabel("HELLO"); public FlyingTextEx() { settitle(",,, "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.setlayout(null); c.addkeylistener(new MyKeyListener()); la.setlocation(50,50); la.setsize(100,20); c.add(la); setsize(300,300); setvisible(true); c.setfocusable(true); c.requestfocus(); class MyKeyListener extends KeyAdapter { public void keypressed(keyevent e) { int keycode = e.getkeycode(); switch(keycode) { case KeyEvent.VK_UP: la.setlocation(la.getx(), la.gety()-flying_unit); break; case KeyEvent.VK_DOWN: la.setlocation(la.getx(), la.gety()+flying_unit); break; case KeyEvent.VK_LEFT: la.setlocation(la.getx()-flying_unit, la.gety()); break; case KeyEvent.VK_RIGHT: la.setlocation(la.getx()+flying_unit, la.gety()); break; c.addmouselistener(new MouseAdapter() { public void mouseclicked(mouseevent e) { Component com = (Component)e.getSource(); com.setfocusable(true); com.requestfocus(); ); public static void main(string [] args) { new FlyingTextEx();

38!, 8! mousepressed(), mousereleased(), mouseclicked()! mousepressed(), mousedragged(), mousedragged(),..., mousedragged(), mousereleased()

39 MouseListener 5 mouseentered(), mouseexited(), mousepressed(), mousereleased(), mouseclicked()! component.addmouselistener(mymouselistener); MouseMotionListener mousedragged(), mousemoved()! component.addmousemotionlistener(mymousemotionlistener);

MouseEvent 40! int getx(), int gety(),! Point getpoint() public void mousepressed(mouseevent e) { int x = e.getx(); int y = e.gety();! int getbutton() public void mousepressed(mouseevent e) { if(e.getbutton() == MouseEvent.BUTTON1) System.out.println("Left Button Pressed");! int getclickcount() public void mouseclicked(mouseevent e) { if(e.getclickcount() == 2) { //

10-9 : 41 class MyMouseListener implements MouseListener, MouseMotionListener { import javax.swing.*; import java.awt.event.*; import java.awt.*; public class MouseListenerAllEx extends JFrame { private JLabel la = new JLabel("No Mouse Event"); public MouseListenerAllEx() { settitle("mouselistener MouseMotionListener "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.setlayout(new FlowLayout()); MyMouseListener listener = new MyMouseListener(); c.addmouselistener(listener); c.addmousemotionlistener(listener); c.add(la); setsize(300,200); setvisible(true); public void mousepressed(mouseevent e) { la.settext("mousepressed ("+e.getx()+", "+e.gety ()+")"); public void mousereleased(mouseevent e) { la.settext("mousereleased("+e.getx()+", "+e.gety()+")"); public void mouseclicked(mouseevent e) { public void mouseentered(mouseevent e) { Component c = (Component)e.getSource(); c.setbackground(color.cyan); public void mouseexited(mouseevent e) { Component c = (Component)e.getSource(); c.setbackground(color.yellow); public void mousedragged(mouseevent e) { la.settext("mousedragged ("+e.getx()+","+e.gety()+")"); public void mousemoved(mouseevent e) { la.settext("mousemoved ("+e.getx()+","+e.gety()+")"); public static void main(string [] args) { new MouseListenerAllEx();

42 10-9

10-10 :. import javax.swing.*; import java.awt.event.*; import java.awt.*; public class ClickAndDoubleClickEx extends JFrame { public ClickAndDoubleClickEx() { settitle("click and DoubleClick "); setdefaultcloseoperation(jframe.exit_on_close); Container c = getcontentpane(); c.addmouselistener(new MyMouseListener()); setsize(300,200); setvisible(true); class MyMouseListener extends MouseAdapter { public void mouseclicked(mouseevent e) { if(e.getclickcount() == 2) { int r = (int)(math.random()*256); int g = (int)(math.random()*256); int b = (int)(math.random()*256); Component c = (Component)e.getSource(); c.setbackground(new Color(r,b,g)); public static void main(string [] args) { new ClickAndDoubleClickEx(); 43

MouseWheelEvent MouseWheelListener 44! MouseWheelEvent MouseWheelListener!! Public void mousewheelmoved(mousewheelevent e) component.addmousewheellistener(new MouseWheelListener() { public void mousewheelmoved(mousewheelevent e) { //. ); 10-7

45