Datalogi A 7: 20/10. Event driven programs Many things may happen: Pressing a button Selecting values with sliders, lists etc. Type text in fields Mouse.

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Intro to Computers!.
Computer Science A 11: 24/3. Animation - Dubble buffering - Transformations - Sprites and textures - Sound.
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
ITEC220 GUI Lecture – Part 2 References  Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9  Java Foundations-Introduction.
CS221 © 2007 Ray S. Babcock Menus, Toolbars, and a Mouse Appendix C.6-C.7.
A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Event Handling Events and Listeners Timers and Animation.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
Computer Science A 8: 6/3. Group data in an object class PlayerData{ String name; int score; }.. PlayerData d=new PlayerData(); d.name=“Mads”; d.score=100;
Chapter 4: Working with Windows Types of Windows –Program Windows –Message Boxes –Dialog Boxes Elements of a Window –Window Panes –Scroll Bars –Menus –Tool.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Introduction to Visual Basic. What is Visual Basic? An environment for developing Windows applications Components –A GUI (Graphical User Interface - gooey)
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Welcome to CIS 083 ! Events CIS 068.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Productivity Programs Common Features and Commands.
Classic Controls Trần Anh Tuấn A. Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Click your mouse for next slide Flash – Morphing and Shape Tweening You have designed some motion animation with the last lesson There is another type.
Introduction to Windows Programming
Exploring Windows and Essential Computing Concepts 1 Windows Desktop u Windows Basics u Icon u Start Button u My Computer u Network Neighborhood u Recycle.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 12 Event-Driven Programming.
MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.
CITA 342 Section 2 Visual Programming. Allows the use of visual expressions (such as graphics, drawings, or animation) in the process of programming.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
Lesson: 2 Common Features and Commands After completing this lesson, you will be able to: Identify the main components of the user interface. Identify.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Event Handling. User actions are called “events” – Low-level window events Window changes – Low-level component events Mouse events, Keyboard events,
PYP002 Intro.to Computer Science Microsoft Word1 Lab 04 - a Microsoft Windows Applications Common Features.
Creating User Interfaces Event-Driven Programming.
Basics of Windows 95/98/NT. Versions of Windows Windows 95 and 98 used mainly on standalone computers Windows NT used on networked computers (as in our.
Simple Clicker App WPF App using C#. App Requirement Need a ‘counter’ display, which starts at 0 Need a ‘clicker’ button ! Pressing the clicker every.
PPT2.01 CREATING AND MODIFYING TEXT AND GRAPHIC OBJECTS Dr. Ennis-Cole.
CSI 3125, Preliminaries, page 1 Event Handling. CSI 3125, Preliminaries, page 2 Event Handling An Event Change in the state of an object is known as event.
Mouse Events GUI. Types of Events  Below, are some of the many kinds of events, swing components generate. Act causing EventListener Type User clicks.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
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.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
HTML FORM. Form HTML Forms are used to select different kinds of user input. HTML forms are used to pass data to a server. A form can contain input elements.
Human Computer Interaction Lecture 07 The Interaction.
Books Introduction A book provides a way to combine recordings into a user friendly web site, allowing the user to browse between recordings.
Human Computer Interaction Lecture 07 The Interaction
Chapter 1: An Introduction to Visual Basic 2015
Personal computer basics
Event Driven Programming
The mouse controls the movement of the pointer on your screen.
ITEC220 GUI Lecture – Part 2 References
Presentation transcript:

Datalogi A 7: 20/10

Event driven programs Many things may happen: Pressing a button Selecting values with sliders, lists etc. Type text in fields Mouse clicks on a canvas Timers Menus Window closing, resizing

JEventQueue My little trick… Usual event-driven programming in Swing requires: Inheritance Interface Inner classes

JEventQueue JEventQueue events = new JEventQueue(); events.listenTo(button1,"button1"); events.listenTo(button2,"button2");... while(true){ EventObject event = events.waitEvent(); String name=events.getName(event); if(name.equals("button1")){... }else if(name.equals("button2")){... }else... }

Example

Event loop JEventQueue events=new JEventQueue(); events.listenTo(button1,"celcius"); events.listenTo(button2,"fahrenheit"); while(true){ EventObject event=events.waitEvent(); String name=events.getName(event); if(name.equals("celcius")){ double f=Double.parseDouble(field2.getText()); field1.setText(""+(f-32)/1.8); }else if(name.equals("fahrenheit")){ double c=Double.parseDouble(field1.getText()); field2.setText(""+(c*1.8+32)); }

Selections: RadioButton: isSelected() CheckBox: isSelected() Spinner: getValue() Slider. getValue() ComboBox: getSelectedItem() List: getSelectedValue()

Text components Generate lots of events: You press ’a’ Key pressed event Key typed event Text field changed event Key released event

Text Components Ignore most of them except: Typing a key that corresponds to a character Pressing a control key: Arrows, Page up/down, function keys etc.

Mouse events Draw circles where you click and lines where you drag. int x0=0,y0=0; while(true){ EventObject event=events.waitEvent(); if(events.isMouseEvent(event)){ int x=events.getMouseX(event); int y=events.getMouseY(event); if(events.isMousePressed(event)){x0=x;y0=y;} if(events.isMouseClicked(event)) canvas.drawOval(x0-5,y0-5,10,10); if(events.isMouseReleased(event)) canvas.drawLine(x0,y0,x,y); }

Timers startTimer(miliseconds,name) stopTimer(name)

Menus frame.setJMenuBar( events.jmenubar(new Font("Arial",Font.PLAIN,18), events.jmenu("File",'F’, events.jmenuitem("New",'n',events.control('N')), events.jmenuitem("Open",'o',events.control('O')), events.jmenuitem("Save",'s',events.control('S')), events.jmenuitem("Save as",'a', events.control('A')), events.jmenuitem("Exit",'x',events.control('Q')) ), events.jmenu("Edit",'E',.. ), events.jmenu("View",'V', )

Menus

Mnemonic: Press Alt-F to get File menu then press ’s’ to save Accelerator key: Press Control-s to save

Window events Events when closing or resizing a window Bring up a dialog when you close a window so that the user can confirm whether the user wants to exit the program.