Chapter 11 - A GUI Interacting With a Problem Domain Class1 Chapter 11 A GUI Interacting With a Problem Domain Class 11.

Slides:



Advertisements
Similar presentations
Java Graphical User Interface (GUI) using Visual Editor in eclipse CSI 1390 – Java Programming Instructor: Saeid Nourian University.
Advertisements

F27SB2 Programming Languages
Deitel Ch 11-part 1 Java GUIs 1 Java GUIs (Deitel, Chap 14-part1) Focus: Attaching GUI components + event handling  input dialog => only one value for.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Graphical User Interfaces Allow for interaction with –Buttons –Menus –Text Fields Two Java Libraries to assist in GUI Programming –AWT –Swing.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L03 (Chapter 15) Creating.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
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.
Lesson 8 Creating Forms with JavaScript
Java Programming Chapter 10 Graphical User Interfaces.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 16.1 Test-Driving the Flag Quiz Application.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
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.
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.
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.
Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 19.1 Test-Driving the Shipping Hub Application.
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.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
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.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 4 – Completing the Inventory Application.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Enhanced Inventory Application.
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,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Object-Oriented Application Development Using VB.NET 1 Chapter 11 Using Multiple Forms with Problem Domain Classes.
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.
Event Handling CS 21a: Introduction to Computing I First Semester,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Object-Oriented Application Development Using VB.NET 1 Chapter 15 Assembling a Three-Tier Windows Application.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Dental Payment Application.
GUIs & Event-Driven Programming Chapter 11 Review.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
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.
A First Look at GUI Applications Radio Buttons and Check Boxes
A First Look at GUI Applications
“Form Ever Follows Function” Louis Henri Sullivan
Processing Timer Events
Graphical User Interface (pronounced "gooey")
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Event Handling CS 21a: Introduction to Computing I
Timer class and inner classes
CiS 260: App Dev I Chapter 6: GUI and OOD.
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Chapter 11 - A GUI Interacting With a Problem Domain Class1 Chapter 11 A GUI Interacting With a Problem Domain Class 11

Chapter 11 - A GUI Interacting With a Problem Domain Class2 1. Adding a New Customer  Develop a new GUI class named AddCustomer to input customer attribute values and then create instances of the Customer class  See Figure 11-4

Chapter 11 - A GUI Interacting With a Problem Domain Class3 Adding a New Customer

Chapter 11 - A GUI Interacting With a Problem Domain Class4 Adding a New Customer  You need to start by importing the classes it uses:  The java.awt class has the Font and Color classes  The javax.swing class contains the GUI components  The ActionEvent and ActionListener interfaces are in the java.awt.event class  JTextField instances are used to input the customer’s name, address, and phone number  JButton instances are used after the customer data is entered, to clear the text fields, and to end processing 11

Chapter 11 - A GUI Interacting With a Problem Domain Class5 Creating the Logo Panel  The JLabel class is used to contain the marina’s logo  The foreground color is set to red using the Color.red constant  The font is set to Times Roman 36 point italic using the “TimesRoman” font name, and the Font.ITALIC constant 11

Chapter 11 - A GUI Interacting With a Problem Domain Class6 Creating the Center Panel  The customer name, address, and phone text boxes are added to the centerPanel  This panel is added to the Frame instance  The SwingConstants class is used to set the alignment  LEFT  RIGHT  CENTER

Chapter 11 - A GUI Interacting With a Problem Domain Class7 Creating the Lower Panel  Three button instances are added to the lower panel to support the Add, Clear, and Close operations  You need to call the addActionListener method for each button to process the events 11

Chapter 11 - A GUI Interacting With a Problem Domain Class8 Handling Events  An anonymous inner class is defined to handle events  The actionPerformed method determines which button was clicked, and then invokes the appropriate method to handle the event

Chapter 11 - A GUI Interacting With a Problem Domain Class9 Using a Dialog Box  If the user clicks the Add button, but hasn’t entered valid data, an error message should be displayed  The statement to display a simple dialog box with a message that requires the user to click the OK button to continue is: JOptionPane.showMessageDialog(this,“message”); 11

Chapter 11 - A GUI Interacting With a Problem Domain Class10 Using a Dialog Box

Chapter 11 - A GUI Interacting With a Problem Domain Class11 2. Finding a Customer (Fig. 11-6)  The FindCustomer class will allow a user to find a customer and then display their address and phone number

Chapter 11 - A GUI Interacting With a Problem Domain Class12 Creating a Vector of Customers  Two vector variables are used to hold a list of customers and their names  The add method is used to add Customer objects to the vector 11

Chapter 11 - A GUI Interacting With a Problem Domain Class13 Using the JList Class  The JList class is used to display a list of customer names  When the user selects a name and then clicks on the Find button, that customer’s name and address are displayed  The JList constructor takes a Vector object which contains the data that is displayed

Chapter 11 - A GUI Interacting With a Problem Domain Class14 Adding Text Fields  JTextField objects are created to display the address and phone number  A JTextField object is used to allow the user to update these values

Chapter 11 - A GUI Interacting With a Problem Domain Class15 3. Adding a Boat  Develop a GUI that allows you to add a new boat to the marina system  You can add a PowerBoat or SailBoat  See Figure 11-13

Chapter 11 - A GUI Interacting With a Problem Domain Class16 Adding a Boat 11

Chapter 11 - A GUI Interacting With a Problem Domain Class17 Adding a Boat 11

Chapter 11 - A GUI Interacting With a Problem Domain Class18 Using Radio Buttons  The radio buttons are used to indicate the type of boat you are adding  The RadioButton constructor takes two arguments  The caption to be displayed  The buttons initial state – true if selected, false otherwise  You can trigger a radio button click event by calling doClick

Chapter 11 - A GUI Interacting With a Problem Domain Class19 Add A Sailboat 11

Chapter 11 - A GUI Interacting With a Problem Domain Class20 Add A PowerBoat

Chapter 11 - A GUI Interacting With a Problem Domain Class21 The clearForm Method  To blank out the text fields use the setText method – pass an empty string as the argument:  manufacturerText.setText(“”); 11