(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

Similar documents
Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

The AWT Package, An Overview

CSIS 10A Assignment 14 SOLUTIONS

Programming Mobile Devices J2SE GUI

GUI in Java TalentHome Solutions

GUI Event Handling 11. GUI Event Handling. Objectives. What is an Event? Hierarchical Model (JDK1.0) Delegation Model (JDK1.1)

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety();

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Programmierpraktikum

The AWT Event Model 9

Advanced Java Programming

G51PRG: Introduction to Programming Second semester Applets and graphics

Java for Interfaces and Networks (DT3010, HT10)

Lecture 5: Java Graphics

AP Computer Science Unit 13. Still More Graphics and Animation.

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Event Driven Programming

Advanced Java Unit 6: Review of Graphics and Events

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Java GUI Design: the Basics

Lecture 3: Java Graphics & Events

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */

Handling Mouse and Keyboard Events

3 Combining Widgets to create Graphical User Interfaces

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

Essential Series. Springer-Verlag London Ltd.

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Applet which displays a simulated trackball in the upper half of its window.

I/O Framework and Case Study. CS151 Chris Pollett Nov. 2, 2005.

Sri Vidya College of Engineering & Technology

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

PIC 20A GUI with swing

1 GUI GUI GUI GUI GUI. GUI(Graphical User Interface) JDK java.awt. ? Component

Java Applets / Flash

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

SD Module-1 Advanced JAVA

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

SD Module-1 Advanced JAVA. Assignment No. 4

cs Java: lecture #5

Chapter 14: Applets and More

Which of the following syntax used to attach an input stream to console?

Computer Programming Java AWT Lab 18

Unit 7: Event driven programming

AP CS Unit 12: Drawing and Mouse Events

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Java. GUI building with the AWT

Java: Graphical User Interfaces (GUI)

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

User interfaces and Swing

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Bean Communication. COMP434B Software Design. Bean Communication. Bean Communication. Bean Communication. Bean Communication

CS 106A, Lecture 14 Events and Instance Variables

Abstract Window Toolkit Overview

Graphical User Interfaces 2

BM214E Object Oriented Programming Lecture 13

ISO-2022-JP (JIS ) 1 2. (Windows95/98 MacOS ) Java UNICODE UNICODE. Java. .java.java.txt native2ascii. .java

Contents. 18 Algorithms Case study: network search The search algorithm Case study: automatic language recognition 57

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

Advanced Java Programming (17625) Event Handling. 20 Marks

Programming graphics

Dr. Hikmat A. M. AbdelJaber

Computer Science 210: Data Structures. Intro to Java Graphics

Programming Languages 2nd edition Tucker and Noonan"

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.

CS 106A, Lecture 14 Events and Instance Variables

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Module 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Graphical User Interfaces 2

The AWT Component Library 10

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Graphical User Interfaces 2

FirstSwingFrame.java Page 1 of 1

CSA 1019 Imperative and OO Programming

Packages: Putting Classes Together

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

COMPSCI 230. Software Design and Construction. Swing

Module 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

PESIT Bangalore South Campus

CS11 Java. Fall Lecture 3

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

The Java Programming Language Basics. Identifiers, Keywords, and Types. Expressions and Flow Control. Object-Oriented Programming. Objects and Classes

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Course: CMPT 101/104 E.100 Thursday, November 23, 2000

MIT AITI Swing Event Model Lecture 17

กล ม API ท ใช. Programming Graphical User Interface (GUI) Containers and Components 22/05/60

Interacción con GUIs

Chapter 1 GUI Applications

An Animated Help System for Java Applets

Graphic User Interfaces. - GUI concepts - Swing - AWT

AP CS Unit 11: Graphics and Events

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

Programming Languages and Techniques (CIS120)

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved.

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Transcription:

51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface ) java.awt AWT Abstract Window Toolkit java.awt Graphics, Color java.awt GUI GUI java.awt GUI (component) GUI GUI (Container) java.awt 6.1 AWT Netscape Sun Microsystems Swing GUI javax.swing.jbutton javax.swing.jtextfield javax.swing.jpanel

52 6!! 6.1 Graphics2D Component java.awt Point, Dimention, Rectangle, Polygon Graphics, Color, SystemColor, Font, FontMetrics, Image, MediaTracker Graphics2D, AlphaCommposite, BasicStroke, Gradient- Paint, TexturePaint, StandardGlyphSet, GraphicsConfiguaration, GraphicsEnvironment, GraphicsDevice AWTEvent, AWTEventMulticaster Component, Button, Label, Checkbox, Choice, List, Canvas, TextComponent, TextField, TextArea, Scrollbar, Container, Panel, ScrollPane, Window, Frame CheckboxGroup, Insets, FlowLayout, BorderLayout, CardLayout, GridLayout, GridBagLayout, GridBagConstraints Menu, MenuItem, CheckboxMenuItem, PopupMenu, MenuShortcut, MenuBar, Cursor, Dialog, FileDiaglog, PrintJob, AWTPermission, Toolkit javax.swing.jframe GUI Java API GUI (event) java Java (delegation) (listener) (adapter) EventListener MouseListener, ActionLister 6.2!! 6.2.1 5.1.1 MouseListener addmouselistener(mouselistener l)

6.2!! 53 6.2.1 6.2.1 (MouseEvent1.java) import javax.swing.timer; import java.awt.event.*; 5 public class MouseEvent1 extends JApplet { int x, vx; Timer timer; 10 public void init(){ x = 0; vx = 1; timer = new Timer(20, new ActionListener(){ public void actionperformed(actionevent e){ if(x < d.width) x += vx; else x = 0; ); 15 20 addmouselistener(new MouseAdapter(){ 25 public void mousereleased(mouseevent e){ timer.restart(); public void mousepressed(mouseevent e){ timer.stop(); 30 ); timer.start(); 35 g.clearrect(0, 0, d.width, d.height); g.drawarc(x, 10, 10, 10, 0, 360); 40 MouseListener 6.2 5 6.2 5 MouseAdapter 6.2.1 25 addmouselistener MouseAdaptor mousepressed mousereleased

54 6!! 6.2 MouseListener mouseclicked mouseentered mouseexited mousepressed mouserelieased 6.3!! 6.3.1 6.2.1 MouseMotionListener addmousemotionlistener(mousemotionlistener l) MouseMotionListener 6.3 2 6.3.1 25 addmousemotionlistener MouseMotionAdaptor mousemoved 6.3 mousedragged mousemoved MouseMotionListener

6.4!! 55 6.3.1 6.3.1 (MouseEvent2.java) import javax.swing.timer; import java.awt.event.*; 5 public class MouseEvent2 extends JApplet { int x, vx; Timer timer; 10 public void init(){ x = 0; vx = 1; timer = new Timer(20, new ActionListener(){ public void actionperformed(actionevent e){ if(x < d.width) x += vx; else x = 0; ); 15 20 addmousemotionlistener(new MouseMotionAdapter(){ 25 public void mousemoved(mouseevent e){ vx = (vx + 1) % 10; ); timer.start(); 30 g.clearrect(0, 0, d.width, d.height); g.drawarc(x, 10, 10, 10, 0, 360); 35 6.4!! 6.4.1 6.4.1 MouseListener mouseclicked MouseEvent getx gety

56 6!! 6.4.1 6.4.1 (MouseEvent3.java) import java.awt.event.*; public class MouseEvent3 extends JApplet { int x, y, w = 10; 5 public void init(){ 10 x = d.width / 2; y = d.height / 2; addmouselistener(new MouseAdapter(){ public void mouseclicked(mouseevent e){ 15 x = e.getx(); y = e.gety(); ); 20 g.clearrect(0, 0, d.width, d.height); 25 g.drawarc(x w / 2, y w / 2, w, w, 0, 360); 6.5!! 6.5.1 300 400 x y = 390 40 10 ( ) 6.5.2 300 400 1 vy 5 y = 0 x 6.5.3 6.5.1 6.5.2 6.5.4 6.5.3 vy > 0 vx 6.5.5

6.6 57 6.5.1 6.5.5 (MouseEvent8.java) import java.awt.color; import java.awt.event.*; 5 public class MouseEvent8 extends JApplet { int red = 0; public void init(){ 10 addmousewheellistener(new MouseWheelListener(){ public void mousewheelmoved(mousewheelevent e){ 15 red =(red + 10)% 256; ); 20 g.clearrect(0, 0, d.width, d.height); g.setcolor(new Color(red, 0, 0)); g.fillarc(10, 10, 10, 10, 0, 360); 25 6.6 6.1 (10, 10) 10 6.2 (0, 0) x 6.3 2 1 () 2 () 6.4 2 2 6.5 10