{ Dating Service ActionHandler Listener class details.

Slides:



Advertisements
Similar presentations
Chapter 8 Improving the User Interface
Advertisements

Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Building Applications Dialogs Passing data between windows Validating Input using FocusListeners.
Copyright W. Howden1 Lecture 7: Functional and OO Design Descriptions.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
1 Name & Gender Example At a certain University the registry require a small application to help those on the front desk work out the gender with the name.
Buttons. Appearance of buttons A button has one of three appearances: Disabled by your program Enabled by your program Enabled by your program and pressed.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L04 (Chapter 15) Creating.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
JOptionPane class. Dialog Boxes A dialog box is a small graphical window that displays a message to the user or requests input. A variety of dialog boxes.
Io package as Java’s basic I/O system continue’d.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
PHP : Hypertext Preprocessor
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.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington GUI and the UI API COMP.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
GUI’s Part Two wxWidgets components. Resources for wxWidgets Sample code on course website wxWidgets web site.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
MSc/PgDip in ITIntroductory Programming: Week 4 Lecture 21 INTRODUCTORY PROGRAMMING Week 4 Lecture 2 Fonts –Horstmann 4.6 ActionEvents –different events.
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,
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington More Interfaces.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington More Interfaces.
Input & Output Functions JavaScript is special from other languages because it can accept input and produce output on the basis of that input in the same.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Validation "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Getting Input. Text Fields A text field is a box that the user can type in Use the JTextField class JTextField tf1 = new JTextField(15); 15 is the field.
SD2054 Software Development. By the end of this lecture you should be able to: Advanced Graphics Programming create pull down menus create combo boxes.
Week101 APCS-AB: Java Miscellaneous Topics: Snippets we missed in Chapters 1-6 of book November 11, 2005.
Chapter 11 - A GUI Interacting With a Problem Domain Class1 Chapter 11 A GUI Interacting With a Problem Domain Class 11.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
Creating a GUI Class An example of class design using inheritance and interfaces.
Graphical User Interfaces (GUI). PART ONE About GUI’s.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
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,
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Object Oriented Programming in Java Habib Rostami Lecture 10.
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.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Modular Event Handling
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.
CompSci 230 S Programming Techniques
3 Introduction to Classes and Objects.
“Form Ever Follows Function” Louis Henri Sullivan
2.5 Another Java Application: Adding Integers
Message, Input, Confirm, and Specialized Dialogs
The structure of Interactive Software
Message, Input, and Confirm Dialogs
Constructors, GUI’s(Using Swing) and ActionListner
Tonga Institute of Higher Education
Chapter 5 Processing Input with Applets
Presentation transcript:

{ Dating Service ActionHandler Listener class details

class ActionHandler implements ActionListener public void actionPerformed(ActionEvent e) { // ***STATUS is a String declared at top of the program if(e.getSource() == statusBox) status = (String)statusBox.getSelectedItem(); if(e.getSource() == genderBox) gender = (String)sexBox.getSelectedItem(); Code to get value selected from the combo boxes: e.getSource is a method that returns what component fired an event. In this case, user selected a combo box option

// This code displays a help message in a dialog box if help button pressed // method e.getActionCommand knows what button is pressed if(e.getActionCommand().equals("HELP")) JOptionPane.showMessageDialog (null, "Select R or S for status and then enter data in all the fields ", "INSTRUCTIONS", JOptionPane.PLAIN_MESSAGE ); A dialog box appears with this message on it "Select R or S for status and then enter data in all the fields ", The parameter “e” knows what component fired an event. In this case, it was the help button

Help Button Dialog Box displays help message to enter data in all the fields

// declare strings at top of actionperformed method for lastname,firstname etc. to store textfields input if(e.getActionCommand().equals("ADD")) { // displays a dialog box telling user to enter data in all fields JOptionPane.showMessageDialog (null, "Be sure data in entered in all the fields", "INSTRUCTIONS", JOptionPane.PLAIN_MESSAGE ); if(status.equalsIgnoreCase("R")) // If user enter R for a regular client.. { // get the age from age textfield – only regular clients have ages age =Integer.parseInt( ageField.getText()); // get all the data from the other textfields using method // getText() as above, e.g. firstname = firstField.getText) // create a Client and add it to the ArrayList and the listModel List.add(client); // Add client to ArrayList listModel.addElement(client); // If successful, add it to Jlist }// close if status else { // do same code for SeniorClient – no age needed } // close else firstField.setText(""); // Reset all textfields to a space } // close add ADD button was pressed, this code follows help button code

ADD BUTTON PRESSED AND DIALOG BOX DISPLAYS “Be sure to enter data in all fields”

Reading in from a file The input file looks like this R (for regular clients ) firstname lastname hobby,..etc..... age S(for Senior Clients firstname lastname hobby etc but no age Algorithm: 1.You have to assemble the fields in the file into a Client or Senior Client based on whether or not the input file entry has an age listed, 2. create a new Client or SeniorClient with the input data 1.You then have to add the Client to the ArrayList ( declared at the top of the program) 2.and also add it to the listmodel ( also set up at the top of the constructor -- this represents the jLIST at the top of the GUI. This part of reading in a client at a time is very similar to the code you use to add a new Client in the listener. except in the listener you will get the client data from the textfields.

// READ IN CLIENTS DATA FROM A FILE (SAMPLE ON MY SITE FOR PROJECT public void BuildService() { Scanner scan = new Scanner(new File("Client1.txt")); Scanner linescan; try { // DECLARE ALL THE VARIABLES NEEDED E.G. LINE, SCAN Client client; // DECLARE CLIENT OBJECTS SeniorClient sclient; while(scan.hasNext()) // CONTINUES UNTIL NO MORE LINES IN FILE { line = scan.nextLine(); // reads in a line from the file System.out.println(line); // for debugging purposes linescan = new Scanner(line); // create and another scanner for input line while (linescan.hasNext()) // while more fields to process { status = linescan.next(); // read in each field Firstname = linescan.next(); Lastname = linescan.next(); sex = linescan.next(); phone = linescan.next(); hobby = linescan.next();

if(status.charAt(0) == 'R')// if we have a regular Client, collect the value in the agefield { // gets the age using linescan.nextInt() // create the Client // Then add to ArrayList and the listModel ( the Jlist at the top of the GUI) } else { //create a SeniorClient using constructor of SeniorClient class // Then add to ArrayList and the listModel (the Jlist at the top of the //GUI) } // add in the try/ catch clauses } } } }// close method