Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,

Slides:



Advertisements
Similar presentations
Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Advertisements

Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Agenda –interfaces and realization –type hierarchy –introduction to graphics and event handling.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Unit 12 Object-oriented programming: Event-driven programming for GUI Jin Sa.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
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.
Intro to Object-Oriented (“OO”) Design. OO Design Simplified methodology 1. Write down detailed description of problem 2. Identify all (relevant) nouns.
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.
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.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Java Programming Chapter 10 Graphical User Interfaces.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
JLabel, JTextField, JButton and JOptionPane
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
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.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
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.
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.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
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.
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 )
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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)
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
SE-1020 Dr. Mark L. Hornick 1 Creating Graphical User Interfaces.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
GUIs and Events Rick Mercer.
CSC 205 Programming II Lecture 5 AWT - I.
CompSci 230 S Programming Techniques
Java Programming: Guided Learning with Early Objects
A First Look at GUI Applications
Processing Timer Events
Graphical User Interface (pronounced "gooey")
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Event-driven programming for GUI
Timer class and inner classes
Graphical user interface-based programming
Basic Elements of The GUI
Graphical User Interfaces in Java Event-driven programming
CiS 260: App Dev I Chapter 6: GUI and OOD.
Graphical User Interface
Presentation transcript:

Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame, JLabel, JTextField, and JButton work.  Become familiar with the concept of event- driven programming. Graphical User Interface (GUI) Components

Java Programming: From Problem Analysis to Program Design, Second Edition2  Discover events and event handlers.  Explore object-oriented design.  Learn how to identify objects, classes, and members of a class. Graphical User Interface (GUI) Components

Java Programming: From Problem Analysis to Program Design, Second Edition3 Graphical User Interface (GUI) Components  View inputs and outputs simultaneously.  One graphical window.  Input values in any order.  Change input values in window.  Click buttons to get output.

Java Programming: From Problem Analysis to Program Design, Second Edition4 Java GUI Components

Java Programming: From Problem Analysis to Program Design, Second Edition5 Graphical User Interface (GUI) Components  GUI components placed in content pane.  GUI components:  Windows  Labels  Text areas  Buttons

Java Programming: From Problem Analysis to Program Design, Second Edition6 GUI Components  Added to content pane of window.  Not added to window itself.  Pixel: A picture element.

Java Programming: From Problem Analysis to Program Design, Second Edition7 Windows  Can be created using a Frame object.  The class Frame provides various methods to control attributes of a window.  Measured in pixels of height and width.  Attributes associated with windows:  Title  Width  Height

Java Programming: From Problem Analysis to Program Design, Second Edition8 class JFrame  GUI window instance created as instance of Frame.  Provides various methods to control window attributes.

Java Programming: From Problem Analysis to Program Design, Second Edition9 Methods Provided by the class JFrame

Java Programming: From Problem Analysis to Program Design, Second Edition10 Methods Provided by the class JFrame

Java Programming: From Problem Analysis to Program Design, Second Edition11 Two Ways to Create a Window  First way:  Declare object of type JFrame.  Instantiate object.  Use various methods to manipulate window.  Second way:  Create class-containing application program by extending definition of class JFrame.  Utilize mechanism of inheritance.

Java Programming: From Problem Analysis to Program Design, Second Edition12 Content Pane  Inner area of GUI window (below title bar, inside border).  To access content pane:  Declare reference variable of type Container.  Use method getContentPane of class JFrame.

Java Programming: From Problem Analysis to Program Design, Second Edition13 Methods Provided by the class Container

Java Programming: From Problem Analysis to Program Design, Second Edition14 class JLabel  Labels: Objects of a particular class type.  class JLabel : Used to create labels.  Label attributes:  Title  Width  Height  To create a label:  Instantiate object of type JLabel.  Modify attributes to control display of labels.

Java Programming: From Problem Analysis to Program Design, Second Edition15 Methods Provided by the class JLabel

Java Programming: From Problem Analysis to Program Design, Second Edition16 Methods Provided by the class JLabel

Java Programming: From Problem Analysis to Program Design, Second Edition17 class JTextField  Text fields: Objects belonging to class JTextField.  To create a text field:  Declare reference variable of type JTextField.  Instantiate object.

Java Programming: From Problem Analysis to Program Design, Second Edition18 Methods Provided by the class JTextField

Java Programming: From Problem Analysis to Program Design, Second Edition19 class JButton  Provided to create buttons in Java.  To create a button:  Use the same technique that is used to create JLabel and JTextField.

Java Programming: From Problem Analysis to Program Design, Second Edition20 Methods Provided by the class JButton

Java Programming: From Problem Analysis to Program Design, Second Edition21 Methods Provided by the class JButton

Java Programming: From Problem Analysis to Program Design, Second Edition22 Handling an Event  Action event: An event created when JButton is clicked.  Event listener: An object that receives a message when JButton is clicked.  In Java, you must register the listener.

Java Programming: From Problem Analysis to Program Design, Second Edition23 Handling an Event  class ActionListener  Handles action event.  Part of package java.awt.Event.  The class ActionListener is a special type of class (interface).  Must contain the actionPerformed method.

Java Programming: From Problem Analysis to Program Design, Second Edition24 Rectangle Program: Sample Run

Java Programming: From Problem Analysis to Program Design, Second Edition25 Programming Example: Temperature Conversion  Input: Temperature in Fahrenheit or Celsius.  Output: Temperature in Celsius if input is Fahrenheit; temperature in Fahrenheit if input is Celsius.

Java Programming: From Problem Analysis to Program Design, Second Edition26 Programming Example: Temperature Conversion Solution: 1.Create the appropriate JLabels, JTextFields, JButtons. 2.Add them to the created content pane. 3.Calculate the appropriate conversions when the buttons are clicked and an event is triggered.

Java Programming: From Problem Analysis to Program Design, Second Edition27 Sample Run for TempConversion

Java Programming: From Problem Analysis to Program Design, Second Edition28 Object-Oriented Design Simplified methodology: 1.Write down detailed description of problem. 2.Identify all (relevant) nouns and verbs. 3.From list of nouns, select objects. 4.Identify data components of each object. 5.From list of verbs, select operations.

Java Programming: From Problem Analysis to Program Design, Second Edition29  Every GUI contains a window.  Various components are added to the content pane of a window.  class Frame is used to create windows.  JLabel is used to label GUI components and display information to user.  JTextFiled is used for input/output.  JButton generates action event.  Action event is sent to action listener.  Action listener must have method called actionPerformed. Summary