A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
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.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Chapter 121 Window Interfaces Using Swing Chapter 12.
GUI and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
GUI Programming in Java
Java Programming Chapter 10 Graphical User Interfaces.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
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.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
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 Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
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.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
ITEC 109 Lecture 27 GUI. GUIs Review Sounds –Arrays hold sample values –Creating a keyboard –Sound effects Homework 3 –The big two –Due after break –Lab.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
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.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
Object Oriented Programming.  Interface  Event Handling.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
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.
1 Lecture 8: User Interface Components with Swing.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
A Quick Java Swing Tutorial
GUI Programming using Java - Event Handling
A First Look at GUI Applications
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

A.k.a. GUI’s

 If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF  I need the hours you spent on your Lab 2  Lab 3 will be graded soon  Lab 4 will be assigned sooner  Questions?  “How to Program Java” By Deitel covers more GUI stuff than the text’s listed on the syllabus

 What are they?  What’s the difference between a GUI and a console based application?  What is a framework? ◦ A process that uses specific objects ◦ Analogous to a car manufacturing process that uses specific car parts.

Answer: A bunch of objects!

 Abstract Windowing Toolkit (AWT) ◦ Built on the native OS ◦ More flexible ◦ Faster ◦ Can be used in browsers without a java plugin  Swing ◦ Newer – built on AWT(ish). Made completely in Java ◦ More Portable ◦ Easier to use ◦ Can use the ‘Model View Control’ design process

 “Swing is a platform-independent, Model- View-Controller GUI framework for Java, which follows a single-threaded programming model. [3]”Model- View-ControllerGUIthreaded [3]  Components –buttons, panels, dialog boxes, menus, text fields, and lists, are the visual widgets that respond to user actions  Swing Components have, ‘J’ in front of them ◦ JFrame ◦ JTextField  Components appear in a container, which are themselves a type of component

 The JComponent class is the root of the swing component hierarchy ◦ All swing components are subtypes of this except for top- level containers such as frames

 We add some objects

 When the button is clicked an Event Object is generated  We handle this with an ActionListener Class

So far the Process is:  Make a window (called a JFrame)  Add stuff to that window ◦ Make the window visible (most important step)  Create an ActionListener  Register the ActionListener

1. Extend/make a JFrame 2. Add a button 3. Make an class that implements ActionListener 4. Give that class to the button  Sound good? Any Issues?  Lets call our Jframe ‘window’  And our ActionListener buttonListener  How does the buttonListener access information/methods in the window object?

 Pane ◦ A content pane is a container that is part of every Jframe object ◦ You cannot see the content pane and it does not have a border, but any object that is to be displayed in a Jframe must be added to the content pane  Panel ◦ A panel is also a container that can hold GUI components ◦ Unlike Jframe objects, panels cannot be displayed by themselves ◦ commonly used to hold and organize collections of related components  You can add a panel to the content pane (Like we did in the example)  Effectively we added a panel to a pane

 An event is an action that takes place within the program ◦ Pressing a button ◦ Hitting ‘Enter’ in a text field  An Event object contains information about the event  The component that generated the event object is known as the Event Source ◦ Jbutton is an event source ◦ Can have multiple listeners  Event objects are automatically passed, as an argument, to the method of the event listener  This process is called ‘Event Firing’

 An event source notifies a registered event listener by calling one of its methods (or event handlers)  The specific event handler that gets called depends on the nature of the event (many event listeners define more than one event handler)  An event object (that encapsulates information relating to the event) is passed to the event handler ◦ Using the information in the event object, the event handler method responds ◦ Every event object includes a getSource() method ◦ All event objects belong to subtypes of the java.util.EventObject class  So what are some of the Event classes?  Besides ‘ActionEvent’

 How does the GUI component know to call action Performed rather than another method?  Every GUI component supports several event types, including mouse events, key events and others.  When an event occurs, the event is dispatched  The private classes that implement the correct type and are properly registered are called

 All event listener class must: ◦ Implement an interface  Java provides numerous interfaces that you can use with event listener classes  The specific interface that you will use depends on the type of event you want to handle  Jbutton components generate action events, and the event listener class that can handle action events is also known as an action listener class  When you write an action listener class for a Jbutton component, it must implement an Interface known as ActionListener  What are some other interfaces?

 Misspelling javax.swing in an import statement  Forgetting to specify an action when the user clicks on the Event Source  Remember that application is not terminated when you close or hide a Jframe. If you want to terminate the application, call setDefaultCloseOperation method and pass Jframe.EXIT_ON_CLOSE as the argument  Forgetting to write an event listener for each event you wish an application to respond to  Forgetting to register an event listener  When writing an event listener method that is required by an interface, not using the method header specified by the interface

 How do you do it?  Setting it to null will allow you to program in absolute terms.

In one sentence what is a Framework? (Do not use an example) What is Swing? Does the order to which you add Java components matter in terms of how they are displayed? List everything that happens in a properly coded GUI program when a JButton is pressed (Use the example from last class) What are the three main Layout managers in Java?

In one sentence what is a Framework? It is a process that uses specific objects What is Swing? Java GUI Library Does the order to which you add Java components matter in terms of how they are displayed? Yes List everything that happens in a properly coded GUI program when a JButton is pressed (Use the example from last class) An event is created A registered ActionListener object is called What are the three main Layout managers in Java? Flow Border Grid