GUI 프로그래밍과 AWT(2) 컴퓨터 공학실험 (I) 인공지능 연구실. 2 AWT Event Model  Java 의 Event Model 1.Event : 사용자가 Program 에 가한 행동 2.Event Source : Event 가 일어난 근원 3.Event.

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Graphical User Interfaces Allow for interaction with –Buttons –Menus –Text Fields Two Java Libraries to assist in GUI Programming –AWT –Swing.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Graphical User Interfaces (GUI) Abstract Windows Toolkit (AWT): java.awt GUI elements: Primitive Button, Label, Checkbox, Scrollbar, etc. Container Panel,
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Introduction to GUI Java offers a great number of pre-defined classes to support the development of graphical user interfaces –These are broken down into.
Combo Box, Check Boxes, and Radio Buttons. Radio Buttons User can click radio buttons, just like other buttons BUT Radio buttons are mutually exclusive.
7-Oct-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : User Interface Components with.
OOP (Java): GUI I/ OOP Objectives – –describe some of the GUI controls and their listeners; more appear in part 13 Semester 2,
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
(c) by Elizabeth Sugar Boese.1 Chapter 12 Events on Components - Lecture Slides.
Java Programming 1 Java Programming II Events, AWT, and Swing.
C13a, AWT Create, display, facilitate user interaction with window objects software framework: a way of structuring generic solutions to common problems.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Objectives of This Session
CSTP FS99CS423 (cotter)1 Java Graphics java.awt.*;
SWING. AbstractButton Swing Buttons are subclasses of the AbstractButton class, which extends JComponent. Abstract class javax.swing.AbstractButton AbstractButton.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
More GUI CSCE 190 – Java Instructor: Joel Gompert Lecture 8 – July 28, 2004.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
GUI Graphical User Interface. Outline Introduction Packages Components Layout Manager Events and Listeners Examples.
Pravin Yannawar, DOCS, NMU Jalgaon. Basic Java : Event handling in AWT and Swing 2 Objectives of This Session Explain the Event handling mechanism & demonstrate.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Class Class 20 Objectives Use JCheckbox, JRadioButton, and a JComboBox in a UID.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially supported by NSF CCLI grant DUE Java: An Eventful Approach An innovative.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
GUI Tutorial 1. A Bit of Philosophy on what to Teach  There are numerous libraries, frameworks, options  Modern GUIs are often developed using XML (e.g.,
Graphical User Interfaces (GUI). PART ONE About GUI’s.
Advanced Java Class Events. change in state initiated by system or user java.util.EventObject java.awt.event java.swing.event.
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
Chapter 6: Events in Java 1.0 Model –Event class –selecting component to handle –handleEvent method –helper methods (action, keyUp, mouseUp, etc.) 1.1.
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
Institute of Ambient Intelligence 2009, Choi, Namseok, Dongseo Univ., Java 기초 ( 컴포넌트와 이벤트 처리 프로그래밍 ) Choi,
Chapter 12: The Abstract Window Toolkit Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 12.
1 IM103 week 8 (C&K ch17, p412) Advanced graphic programming Learning objectives By the end of this chapter you should be able to:  create dialogue windows.
OOSD Using Java GUI Programming. Components & Containers.
1 Chapter 13 – More GUI Components Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides users with basic.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
TENTH LECTURE Event and listener. Events and Listeners An event can be defined as a type of signal to the program that something has happened. The event.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
Dept. of CSIE, National University of Tainan 10/21/2012 Responding to User Input.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
GUI Programming in Java Hao Jiang Boston College April, 2009.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
Modular Event Handling
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
CSC 205 Programming II Lecture 5 AWT - I.
GUI building with the AWT
It attached with method ,class and interface etc…
Event Handling Chapter 2 Objectives
AWT Components.
Abstract Window ToolKit (AWT)
AWT.
Introduction to Event Handling
GUI building with the AWT
Graphics Programming - Frames
어서와 Java는 처음이지! 제13장 실전프로젝트.
Programming Graphical User Interface (GUI)
GUI building with the AWT
Presentation transcript:

GUI 프로그래밍과 AWT(2) 컴퓨터 공학실험 (I) 인공지능 연구실

2 AWT Event Model  Java 의 Event Model 1.Event : 사용자가 Program 에 가한 행동 2.Event Source : Event 가 일어난 근원 3.Event Handler : 발생된 Event object 를 받아 적당한 행동을 취 하는 method

3 Event Handler(1)  import java.awt.*;  public class ButtonTest {  public static void main(String args[]) {  Frame f = new Frame("Button Test"); //Frame 생성  Button b = new Button(“ 버튼 1"); //Button 생성  b.addActionListener(new ButtonHandler()); //addActionListener() method 는 이 Button 에 Event Handler 를 지정  f.add(b, "Center");  f.pack();  f.setVisible(true);  }

4 Event Handler(2) 1.import java.awt.event.*; 2. public class ButtonHandler implements ActionListener { // interface 안에 있는 특정한 abstract method 를 구현 3. public void actionPerformed(ActionEvent e) { 4. System.out.println("Button 을 클릭하셨네요."); 5. System.out.println("Button 에 적힌 글은 " + e.getActionCommand()); 6. } 7.} – Event Handler 를 만들 때는 반드시 적당한 Event Handler Interface 를 implements 해야 한다 – addXXXListener() 의 argument 로 올 Event Handler class 는 반드시 XXXListener interface 를 implements 해야 한다.

5 Method Categories and Interfaces

6 AWT Component –Button –Checkbox –CheckboxGroup –Choice –Canvas –Label –TextField –TextArea –List –Dialog –ScrollPane –Menu

7 AWT Component(1) - Button import java.awt.*; import java.awt.event.*; public class ButtonTest { Frame f ; Button b; public static void main(String args[]) { ButtonTest bt = new ButtonTest(); bt.go(); } public void go() { f = new Frame("Button Test"); b = new Button(“ 확인 "); b.addActionListener(new ButtonHandler()); f.add(b, "Center"); f.pack(); f.setVisible(true); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equals(" 확인 ")) {….} // if (ae.getSource()==b){….} }

8 AWT Component(2) – Check Box public class SampleCheckbox implements ItemListener { private Frame f; private Checkbox one, two; public void go() { f = new Frame("Sample Checkbox"); one = new Checkbox(“AI", true); two = new Checkbox(“Lab", false); one.addItemListener(this); two.addItemListener(this); …….. } public void itemStateChanged(ItemEvent ie) { String state = " 해제 "; if (ie.getStateChange() == ItemEvent.SELECTED) { state = " 선택 "; } System.out.println (ie.getItem() + " " + state); }

9 AWT Component(3) – Radio Button public class TestCheckboxGroup implements ItemListener { private Frame f; private Checkbox one, two, three; private CheckboxGroup cbg; public void go() { f = new Frame("Sample Checkbox"); cbg = new CheckboxGroup(); one = new Checkbox(" 대 ", cbg, true); two = new Checkbox(" 중 ", cbg, false); three = new Checkbox(" 소 ", cbg, false); ////////////////////////////// swing 에서는 JRadioButton one.addItemListener(this); two.addItemListener(this); three.addItemListener(this); ……… } public void itemStateChanged(ItemEvent ev) { String state = null; if (ev.getStateChange() == ItemEvent.SELECTED) { state = " 가 선택됨 "; System.out.println (ev.getItem() + " " + state); }

10 AWT Component(3) – Combo Box public class SampleChoice implements ItemListener { private Frame f; private Choice choice; ///////// swing 에서는 JComboBox public void go() { f = new Frame("Choice 연습 "); choice = new Choice(); choice.addItem(“AI"); choice.addItem(“Lab"); choice.addItem(" 인공지능연구실 "); choice.addItemListener(this); ……… } public void itemStateChanged(ItemEvent ev) { String state = "deselected"; if (ev.getStateChange() == ItemEvent.SELECTED) { state = "selected"; } System.out.println (ev.getItem() + " " + state); }

11 AWT Component(3) – Canvas public class CanvasTest extends Canvas implements KeyListener{ int x=10, y=10, xh=10, yh=10; public void paint(Graphics g) { g.drawRect(x, y, xh, yh); } public void keyTyped(KeyEvent ev) { if (ev.getKeyChar() == 'j') { x -= 1; x -= 1; } else if (ev.getKeyChar() == 'l') { x += 1; x += 1; } else if (ev.getKeyChar() == 'k') { y += 1; y += 1; } else if (ev.getKeyChar() == 'i') { y -= 1; y -= 1; } repaint(); } public void keyPressed(KeyEvent ev) { } public void keyReleased(KeyEvent ev) { } public static void main(String args[]) { Frame f = new Frame("Canvas"); CanvasTest mc = new CanvasTest(); mc.setSize(150, 150); f.add(mc, BorderLayout.CENTER); mc.requestFocus(); mc.addKeyListener(mc); f.pack(); f.setVisible(true); }

12 AWT Component(3) – Label import java.awt.*; public class LabelTest{ public static void main(String args[]) { Frame f = new Frame(" 이게 Label 입니다."); Label lb = new Label(" 사원정보 "); f.add(lb); f.pack(); f.setVisible(true); }

13 AWT Component(3) – Text Field import java.awt.*; import java.awt.event.*; public class TextFieldTest { private Frame f; private TextField tf; public void go() { f = new Frame("TextField Test"); tf = new TextField(30); tf.setEchoChar('*'); f.add(tf, BorderLayout.CENTER); f.pack(); f.setVisible(true); } public static void main (String args[]) { TextFieldTest tft = new TextFieldTest(); tft.go(); }

14 AWT Component(3) – Text Area import java.awt.*; import java.awt.event.*; public class TextAreaTest implements ActionListener { private Frame f; private TextArea ta, tac; private Button ok; public void go() { f = new Frame("TextArea"); ta = new TextArea("Hello!", 4, 30); tac = new TextArea(4, 30); ok = new Button(" 복사 "); f.add(ta, BorderLayout.NORTH); f.add(ok, BorderLayout.CENTER); f.add(tac, BorderLayout.SOUTH); ok.addActionListener(this); f.pack(); f.setVisible(true); } public void actionPerformed(ActionEvent av) { String text = ta.getText(); tac.setText(text); } public static void main (String args[]) { TextAreaTest tt = new TextAreaTest(); tt.go(); }

15 AWT Component(3) – List import java.awt.*; import java.awt.event.*; public class TestList implements ActionListener { private Frame f; private List list; private Button b; public void go() { f = new Frame(“List"); list = new List(4, true); list.add(“AI"); list.add(“Lab"); list.add(" 인공지능연구실 "); b = new Button(" 눌러 ~ 눌러 ~"); f.add(list, BorderLayout.CENTER); f.add(b, BorderLayout.SOUTH); b.addActionListener(this); f.pack(); f.setVisible(true); } public void actionPerformed(ActionEvent ae) { String [] selectedItems; selectedItems = list.getSelectedItems(); for (int i = 0; i < selectedItems.length; i++) System.out.println(selectedItems[i]); } public static void main (String args[]) { TestList ml = new TestList(); ml.go(); }

16 AWT Component(3) – Dialog Box import java.awt.*; import java.awt.event.*; public class TestDialog implements ActionListener { private Frame f; private FileDialog fd; private Dialog dl; private Button b1, b2, close; public void go() { f = new Frame("FileDialog"); fd = new FileDialog(f, " 파일 열기 ");// Dialog 만들기 dl = new Dialog(f, "dialog", true); dl.add(new Label(" 여러분 안녕 ?"), BorderLayout.NORTH); close = new Button(" 닫 기 "); close.addActionListener(this); dl.add(close, BorderLayout.CENTER); dl.pack(); b1 = new Button("FileDialog"); b2 = new Button("Dialog"); b1.addActionListener(this); b2.addActionListener(this); f.add(b1, BorderLayout.CENTER); f.add(b2, BorderLayout.EAST); f.pack(); f.setVisible(true); } public void actionPerformed( ActionEvent ae) { String buttonPressed = ae.getActionCommand(); if (buttonPressed.equals("FileDialog")) { fd.setVisible(true); } else if (buttonPressed.equals("Dialog")) { dl.setVisible(true); } else if (buttonPressed.equals(" 닫 기 ")) { dl.setVisible(false); } else { fd.setVisible(false); } } public static void main (String args[]) { TestDialog TestDialog = new TestDialog(); TestDialog.go(); }

17 AWT Component(3) – ScrollPane import java.awt.*; public class TestScrollPane { private Frame f; private Image img; private Button b1, b2, b3, b4, b5, b6; private Button b7, b8, b9, b10, b11, b12; private Panel p; private ScrollPane sp; public void go() { f = new Frame("Sample ScrollPane"); p = new Panel(); sp = new ScrollPane(); p.setLayout(new GridLayout(4,3)); b1 = new Button(" 사람 1"); b2 = new Button(" 사람 2"); b3 = new Button(" 사람 3"); b4 = new Button(" 사람 4"); b5 = new Button(" 사람 5"); b6 = new Button(" 사람 6"); b7 = new Button(" 사람 7"); b8 = new Button(" 사람 8"); b9 = new Button(" 사람 9"); b10 = new Button(" 사람 10");b11 = new Button(" 사람 11");b12 = new Button(" 사람 12"); p.add(b1); p.add(b2); p.add(b3); p.add(b4); p.add(b5); p.add(b6); p.add(b7); p.add(b8); p.add(b9); p.add(b10); p.add(b11); p.add(b12); sp.add(p); f.add(sp, BorderLayout.CENTER); f.setSize(100,100); f.setVisible(true); } public static void main (String args[]) { TestScrollPane TestScrollPane = new TestScrollPane(); TestScrollPane.go(); }