Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially supported by NSF CCLI grant DUE-0088895 Java: An Eventful Approach An innovative.

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.
Programming in Java; Instructor:John Punin Graphics and Graphical User Interfaces1 Programming in Java Graphics and Graphical User Interfaces.
Graphic User Interfaces Layout Managers Event Handling.
TCU CoSc Programming with Java Handling Events.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
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,
Chapter 121 Window Interfaces Using Swing Chapter 12.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
CPSC150 JavaLynn Lambert CPSC150 Week 12 InheritanceInterfaces.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Java Programming Chapter 10 Graphical User Interfaces.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
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.
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,
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
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.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
1 Lesson: Applets with User Input and Output with GUI ICS4M.
Layout Managers Arranges and lays out the GUI components on a container.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java Applet Basics (2). The Body Mass Index Calculator.
Object Oriented Programming.  Interface  Event Handling.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS Lecture 7-3 A picture's worth a thousand words.
Computer Science 209 GUIs Model/View/Controller Layouts.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
Graphical User Interfaces (GUI). PART ONE About GUI’s.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
Event Handling CS 21a: Introduction to Computing I First Semester,
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
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.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
GUIs and Events Rick Mercer.
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.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
Event Handling CS 21a: Introduction to Computing I
GUI building with the AWT
GUI building with the AWT
A picture's worth a thousand words
Presentation transcript:

Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially supported by NSF CCLI grant DUE Java: An Eventful Approach An innovative approach to teaching Java in CS1 † Interfaces & GUI Components

Interfaces Provide support for abstraction. Provide contract for implementing classes. Allow variables to hold values from different classes. Necessary for standard Java event handling.

Interfaces for Abstraction Variable with class type can only hold objects from class or its extension. Classes implementing same interface need not share any code. Like purely abstract class but more flexible as class can implement several interfaces. Laundry Demo.

The Need for Input or Interaction Useful for examples –Frogger with mouse clicks –Anticipating array examples: Snake, Simon –No way to get text input up to this point Midterm / Test Program time –Nice break –Less conceptually demanding than other topics

GUI Components –Button, Choice, Scrollbar –Label, TextField, TextArea Associated Listeners Layout -- not emphasized –FlowLayout, BorderLayout, GridLayout Panels

Layout Managers WindowController uses BorderLayout add(component,BorderLayout.SOUTH);

“How to” GUI Checklist Create and initialize the component. Install the component in a container (window or panel). Associate listener with component and ensure its class implements appropriate listener interface. Write listener method.

Simple Listeners Only No inner classes Controller or WindowController is listener –Analogy with mouse event handling methods

Button Constructor takes label as parameter. –new Button(“button label”) Associated with ActionListener –addActionListener(this); –class … implements ActionListener; Listener method is actionPerformed taking ActionEvent as a parameter. –public void actionPerformed(ActionEvent evt){

Button public class SimpleGUI extends WindowController implements ActionListener { // 3 private Button myButton; // 1 public void begin() { myButton = new Button(“Push me!”); // 1 add(myButton, BorderLayout.SOUTH); // 2 myButton.addActionListener(this); // 3 } public void actionPerformed(ActionEvent evt) { new Text(“That tickles!”,150,75,canvas); // 4 }

Panels Organize window w/nested Panels. Fixes stretching problem of BorderLayout. Add GUI components to panel, add panel to window. Panel uses FlowLayout by default –Add GUI components left-to-right in order added. Start new row when out of space.

Button in Panel public class SimpleGUI extends WindowController implements ActionListener { // 3 private Button myButton; // 1 public void begin() { Panel southPanel = new Panel(); myButton = new Button(“Push me!”); // 1 southPanel.add(myButton); add(southPanel, BorderLayout.SOUTH); // 2 myButton.addActionListener(this); // 3 } … }

GUI cheat sheet For each component: –Constructor –GUI methods –Listener and event methods Choice, Scrollbar, Label, TextField, TextArea Also cover key and mouse events

Choice Menu Constructor takes label as parameter. –new Choice(); –add(“item name”); Associated with ItemListener –addItemListener(this); –class … implements ItemListener; Listener method is itemStateChanged: –public void itemStateChanged(ItemEvent evt){ Get label with getSelectedItem() –String item = myChoice.getSelectedItem();