Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)

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.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Agenda –interfaces and realization –type hierarchy –introduction to graphics and event handling.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Chapter 5: Keyboard I/O & Simple GUI’s Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002,
Chapter 8 User-Defined Classes and ADTs. Chapter Objectives Learn about classes Learn about private, protected, public, and static members of a class.
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
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.
Chapter 121 Window Interfaces Using Swing Chapter 12.
COMP 110 Introduction to Programming Mr. Joshua Stough October 1, 2007.
Intro to Object-Oriented (“OO”) Design. OO Design Simplified methodology 1. Write down detailed description of problem 2. Identify all (relevant) nouns.
Software Engineering Principles and C++ Classes
Chapter 8: User-Defined Classes and ADTs J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
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.
COMP 14 Introduction to Programming Miguel A. Otaduy May 24, 2004.
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.
Java Programming Chapter 10 Graphical User Interfaces.
Java Programming, 2E Introductory Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
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.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
GUI programming Graphical user interface-based programming.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Data Structures Using C++1 Chapter 1 -Software Engineering Principles -ADT and Classes.
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.
Chapter 8: User-Defined Classes and ADTs
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 ( 李德成 )
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
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)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
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.
Data Structures Using Java1 Chapter 1 Software Engineering Principles and Java Classes.
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.
CSC 205 Programming II Lecture 5 AWT - I.
Java Applet What is a Java Applet? How is applet compiled?
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
User-Defined Classes and ADTs
Graphical user interface-based programming
User-Defined Classes and ADTs
Graphical User Interfaces in Java Event-driven programming
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 5 Processing Input with Applets
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)

Chapter Objectives Learn about basic GUI components Explore how the GUI components Frame, Label, Textile, and JButton work Become familiar with the concept of event- driven programming

Chapter Objectives 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 View inputs and outputs simultaneously One graphical window Input values in any order Change input values in window Click on buttons to get output

Java GUI Components

Graphical User Interface (GUI) Components GUI components placed in content pane GUI components –Windows –Labels –Text areas –Buttons

GUI Components Added to content pane of window Not added to window itself Pixel: picture element

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

class Frame GUI window instance created as instance of Frame Provides various methods to control window attributes

Methods Provided by the class Frame

Two Ways to Create a Window First way –Declare object of type Frame –Instantiate object –Use various methods to manipulate window Second way –Create class containing application program by extending definition of class Frame –Utilizes mechanism of inheritance

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 Frame

Methods Provided by the class Container

class Label Labels: objects of particular class type class Label: used to create labels Label attributes –title –width –height To create a label –Instantiate object of type Label –Modify attributes to control display of labels

Methods Provided by the class Label

class Textile Text fields: objects belonging to class Textile To create text field –Declare reference variable of type Textile –Instantiate object

Methods Provided by the class Textile

class JButton Provided to create buttons in Java To create button –Same technique as creating Label and Textile

Methods Provided by the class JButton

Handling an Event Action event: event created when JButton is clicked Event listener: object which receives message when JButton is clicked In Java, you must register the listener

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 actionPerformed method

Rectangle Program: Sample Run

Programming Example: Temperature Conversion Input: temperature in Fahrenheit or Centigrade Output: temperature in Centigrade if input is Fahrenheit; temperature in Fahrenheit if input is Centigrade

Programming Example: Temperature Conversion Solution: –Create the appropriate JLabels, JTextFields, JButtons –Add them to the created content pane –Calculate the appropriate conversions when the buttons are clicked and an event is triggered

Sample Run for TempConversion

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

Object-Oriented Design Example 1 Problem Statement –Write a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle Nouns –Length, width, rectangle, perimeter, area

class Rectangle with Data Members and Operations

Object-Oriented Design Example 2 A place to buy candy is from a candy machine. A new candy machine is bought for the gym, but it is not working properly. The candy machine has four dispensers to hold and release items sold by the candy machine and a cash register. The machine sells four products —candies, chips, gum, and cookies—each stored in a separate dispenser. You have been asked to write a program for this candy machine so that it can be put into operation.

Object-Oriented Design Example 2 The program should do the following: Show the customer the different products sold by the candy machine. Let the customer make the selection. Show the customer the cost of the item selected. Accept money from the customer. Return change. Release the item, that is, make the sale.

Object-Oriented Design Example 2

Implementing Classes and Operations Algorithms are used to implement operations Construct and implement your own methods classes Integer, Double, Character, Long, Float –Known as wrapper classes –Provided so that values of primitive data types can be treated as objects –Have limitations (cannot change value stored in objects)

The class IntClass

Chapter Summary Every GUI contains a window Various components are added to content pane of window class Frame is used to create windows Label is used to label GUI components and display information to user Textile is used for input/output JButton generates action event Action event is sent to action listener Action listener must have method called actionPerformed

Chapter Summary class: collection of data members and methods associated with those members Object-Oriented Design (OOD) –Starts with a problem statement –Identifies classes required with nouns in problem statement –Identifies methods required with verbs in problem specification