Ellen Walker Hiram College

Slides:



Advertisements
Similar presentations
Graphic User Interfaces Layout Managers Event Handling.
Advertisements

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.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
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.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Welcome to CIS 083 ! Events CIS 068.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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.
GUI programming Graphical user interface-based programming.
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,
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.
Layout Managers Arranges and lays out the GUI components on a container.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Object Oriented Programming.  Interface  Event Handling.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
A simple swing example GETTING STARTED WITH WIND CHILL.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Review_6 AWT, Swing, ActionListener, and Graphics.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
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.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
Event Handling CS 21a: Introduction to Computing I First Semester,
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.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
GUIs & Event-Driven Programming Chapter 11 Review.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
A Quick Java Swing Tutorial
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.
Graphical User Interfaces
CompSci 230 S Programming Techniques
Graphical User Interfaces -- GUIs
Web Design & Development Lecture 11
A First Look at GUI Applications
“Form Ever Follows Function” Louis Henri Sullivan
Java GUI.
Graphical User Interface (pronounced "gooey")
A Quick Java Swing Tutorial
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Event-driven programming for GUI
Timer class and inner classes
Graphical user interface-based programming
A Quick Java Swing Tutorial
Constructors, GUI’s(Using Swing) and ActionListner
Graphical User Interface
Presentation transcript:

Ellen Walker Hiram College Java GUI Programming 1 Ellen Walker Hiram College

What is a GUI? Graphical User Interface Easier (for most people) to use More complex to program

Why Java? Java compiles for a virtual machine “Write once run anywhere” One program looks nice on: Linux Windows Macintosh Can also generate “applets” to run from Web pages (not today)

GUI Programs are Event Driven Signal that something “interesting” has happened Example: user presses a button, user moves the mouse Main program reacts to events while(true){ Wait for an event React to it }

Sequential vs Event-Driven Programmer is in complete control Program causes a sequence of actions Event driven User is in complete control User causes events, events cause program actions “flow of control” - control structures vs. events

Major Libraries Used Abstract Window Toolkit (java.awt.*) - for generating graphics Rectangle, Polygon, etc. AWT events (java.awt.event.*) ActionEvent, MouseEvent, etc. SWING (javax.swing.*) - for generating units to interact with (some units generate events) Frames (windows) Buttons Labels & Text information

Some Swing Classes JFrame JLabel JTextField JTextArea JButton Represents window with title & border JLabel Displays text or an image (cannot be changed) JTextField Area for the user to enter one line of text JTextArea Area for the user to enter multiline text JButton A push button (to connect to an action)

Structure of a GUI Program Main method Creates an instance of a GUI class GUI class (implements ActionListener) Constructor configures components Action Performer processes events Event dispatcher The while loop that waits for events and calls the action performer You don’t have to write this. Other listeners exist, e.g. window listener, mouse listener

WindChill Calculator Puts up a window with 1 JTextArea (not to be edited) 3 Jlabels (F temp., wind, windchill) 3 JTextFields (one for each label) 1 Jbutton (“Run) When “Run” is clicked, windchill temp. is computed & displayed in its field, using text from F temp & wind fields Run this.

WindChill Calculator Pseudocode public class Windchill implements ActionListener { static final variables for setup info instance variables for components window, labels, textfields, etc. public Windchill() //constructor public void actionPerformed(ActionEvent e) //event processor }

Constructor Configure GUI window.setVisible(true); //after all that! Set window size & default close operation Specify properties of objects, e.g. legendArea is not editable Register event listener (associate it with the button that sends the event) Arrange components in the GUI window.setVisible(true); //after all that!

Registering Event Listeners Every object that can send an event needs to be associated with a Listener object that processes that event (using its ActionPerformed method) Usually, the code to set this up is in the Listener’s constructor Example (“this” is the ActionListener class): runButton.addActionListener(this);

Arranging Interface Objects Every JFrame has a LayoutManager that determines locations of new components FlowLayout - each added object goes to the right of previous object (or below if there isn’t room to the right) GridLayout - objects are arrayed in a specified number of columns and/or rows JFrame’s add method places each interface component according to the layout E.g. window.add(legendArea);

ActionPerformed Takes one parameter, an ActionEvent In this case: One ActionPerformed method can handle several different actions (using a case statement) In this case: Event is when runButton is pressed Action is to compute the windchill and display it in the appropriate text area