Object-Oriented Software Engineering

Slides:



Advertisements
Similar presentations
FH-Hof Dialoge Richard Göbel. FH-Hof Inhalt JDialog Vordefinierte Dialoge File Browser.
Advertisements

Building Applications Dialogs Passing data between windows Validating Input using FocusListeners.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
Object-Oriented Software Engineering PersonGui (Mark 2) Case Study.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
CS288 Lab Exercise 1. UniS Open PersonGui Files Go to Course web site for PersonGui source files
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.
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.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
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 Object-Oriented Software Engineering CS GUI building with NetBeans Contents User Interaction JButtons JTextFields JLabels JForms in NetBeans Practical.
More Event Handling Adapters Anonymous Listeners Pop menus Validating User Input.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 25 – Ticket Information Application Introducing.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
CHAPTER:07 JAVA IDE PROGRAMMING-II Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
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.
SD2054 Software Development. By the end of this lecture you should be able to: Advanced Graphics Programming create pull down menus create combo boxes.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
CS 415 N-Tier Application Development By Umair Ashraf June 25,2013 National University of Computer and Emerging Sciences Lecture # 4 Web Presentation Patterns.
Object-Oriented Software Engineering Using Threads and simple Animation.
Software Construction LAB 08 Java Programming with SWING GUI Builder.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
JOptionPane Class JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something. While the JOptionPane.
Lecture 33: More Graphical User Interface (GUI) Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26.
Creating and Using Dialogs ● A dialog is a box that pops up and prompts the user for a value or informs them of something ● One way: directly create objects.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Graphical User Interface (GUI)
Overview Project 2 JFileChooser StringTokenizers Vectors/arrays.
Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..
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.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
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:
Dept. of CSIE, National University of Tainan 10/21/2012 Working with Swing.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Object-Oriented Software Engineering
A Quick Java Swing Tutorial
Modular Event Handling
CompSci 230 S Programming Techniques
CompSci 280 S Introduction to Software Development
Building a Swing Interface
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
A First Look at GUI Applications
“Form Ever Follows Function” Louis Henri Sullivan
Object-Oriented Programming (Java), Unit 23
2.5 Another Java Application: Adding Integers
Graphical User Interface (pronounced "gooey")
Java Programming JFileChooser AudioPlayer2 Timer RandomAccessFile
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Message, Input, Confirm, and Specialized Dialogs
JOptionPane Dialogs javax.swing.JOptionPane is a class for creating dialog boxes. Has both static methods and instance methods for dialogs. Easy to create.
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
CS18000: Problem Solving and Object-Oriented Programming
CS288 Lab Exercise 3.
CS288 Lab Exercise 1.
Message, Input, and Confirm Dialogs
Steps to Creating a GUI Interface
CS288 Lab Exercise 2.
A Quick Java Swing Tutorial
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
Component-Based Software Engineering
Object-Oriented Software Engineering
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

Object-Oriented Software Engineering PersonGui (Mark 2) Case Study (cntd)

Contents PersonGui (Mark 2) Class Daigram PersonMaker Class Handling user input with dialogs Sequence Diagram for Dailogs Show Person Attributes Sequence Diagram Person Class Diagram Person Constructor Sequence Diagram JFileChooser

Class Diagram JPanel JTextArea ActionListener JToolBar JScrollPane <<interface>> ActionListener JTextArea 1 JToolBar 1 JScrollPane PersonGui 1 JTextField 1 JFrame 1 <<abstract>> MouseAdapter PersonMaker 1 1 * PopupListener Person

<<interface>> The PersonMaker Class JPanel <<interface>> ActionListener JToolBar PersonGui PersonMaker Basic classes defining application Person

PersonMaker Class PersonGui Mark 1 Could only display one set of attributes. Only needed one instance of Person class.

PersonMaker Class PersonGui Mark 2 Creates many instances of Person. PersonMaker manages this functionality on behalf of the PersonGui class

PersonMaker Use Case user Define Age :PersonGui dude:PersonMaker setAge(ageString);

PersonMaker setAge method public void setAge (String stringAge) { string_age = stringAge; try { age = new Double(stringAge); } catch (NumberFormatException exp1) { string_age = handleTextInput("Age"); //Why could this result in an error? age = new Double(string_age); } instance field, stores original string so that if numeric value is flawed can still refer to original during lifetime of object Attempt to convert string to numeric value of type Double. Exception causes dialog box via handleTextInput. See Lecture 5 for exception handling. Full code available on web site

PersonMaker handleTextInput public String handleTextInput (String dis_text) { String s = (String)JOptionPane.showInputDialog( null, dis_text, "PersonMaker Class", JOptionPane.PLAIN_MESSAGE, "Fluffy"); return s; }

PersonMaker handleTextInput JOptionPane.showInputDialog causes this dialog to appear

handleTextInput Sequence Diagram Option Dialog has anonymous buttons Static method, invoked on class not object dude: PersonMaker :JButton JOptionPane showInputDialog( ) left_mouse_click e:Action Event <<create>> notify(e ) query event String s Represents approximately events that occur in handleTextInput

<<include>> PersonMaker Use Case PersonGui dude:Person Make_Person( ) user text Display Attributes in seperate JFrame Choose Image for Person <<include>>

containing attributes public String Make_Person ( ) { Show_Attributes_InFrame ( ); return "This Person has these attributes: \n " + "\n\tFirst Name \t= " + getFirstName( ) + "\n\tLast Name \t= " + getLastName( ) + "\n\tHeight \t= " + getPersonHeight( ) + "\n\tAge \t= " + getPersonAge( ) + "\n"; } Calls internal method to construct JFrame containing attributes Returns composite string of attributes to be displayed in JTextArea

Show_Attributes_InFrame newContentPane :Person dude:Person frame:JFrame <<create>> Content Pane of JFrame is instance of Person Class. (This class is responsible for choice of image.) <<create>> setContentPane (newContentPane) pack( ) setVisible(true) Three classes used to create JFrame and its contents. Shows contents of JFrame can be completely separate from its container

<<interface>> Person Class Diagram <<interface>> ActionListener JPanel Person GridBagLayout File JFileChooser Depends on these classes. I.e. has local fields that are instances of these classes. See lecture 6 for more details.

Person Constructor Sequence Diagram file:File <<create>> fc:JFileChooser <<create>> getSelectedFile( ) file label_drag: JLabel <<create>> from dragon dragon: ImageIcon <<create>> from imgURL imgURL: java.net.URL <<create>> from icon_file_name getCanonicalPath( ) icon_file_name Finally add new JLabel to GridBagLayout. Note this is only approximate description.

Creating an ImageIcon When creating ImageIcon from a string value, need to use different code than that of the createImageIcon method try { java.net.URL imgURL = new URL("file:///"+icon_file_name); dragon = new ImageIcon(imgURL, "new icon image"); label_drag = new JLabel(dragon); } catch (java.net.MalformedURLException exp1) { System.out.println("MalformedURLException : \n" + icon_file_name + "\n====\n"); } Section of code in Person constructor that makes an ImageIcon from the string given by the JFileChooser

The JFileChooser Class int returnVal = fc.showOpenDialog(Person.this); Returns an integer. Also uses static fields to store data about choice of file for later use.

JFileChooser Class Diagram JComponent JFileChooser public static int APPROVE_OPTION public static int CANCEL_OPTION public void showOpenDialog(Component parent) public File getSelectedFile( ) (Only some of the fields and methods are shown here)

JFileChooser Constructor JFileChooser(File currentDirectory) Constructs a JFileChooser using the given File as the path. JFileChooser() Constructs a JFileChooser pointing to the user's default directory. String cwd = "images"; file = new File(cwd); if (file != null) { fc = new JFileChooser(file); } else { fc = new JFileChooser(); }

The approve option int returnVal = fc.showOpenDialog(Person.this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); // now do something with the file // in our case create an icon image from it }

The cancel option int returnVal = fc.showOpenDialog(Person.this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); // now do something with the file // in our case create an icon image from it } else if (returnVal == JFileChooser.CANCEL_OPTION ) { // now do something in case where user // cancels selection }