CS 209 Spring, 2006 Lab 8: GUI Development Instructor: J.G. Neal

Similar documents
CS 209 Sec. 52 Spring, 2006 Lab 6 - B: Inheritance Instructor: J.G. Neal

CS 209 Spring, 2006 Lab 11: Files & Streams Instructor: J.G. Neal

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

CS 209 Sec. 52 Spring, 2006 Lab 5: Classes Instructor: J.G. Neal

CS 209 Sec. 52 Spring, 2006 Lab 4-A: Arrays Instructor: J.G. Neal Objectives: Lab Instructions: Obtain file ArrayDemoConsole.java

CoSc Lab # 6 (The Model) Due Date: Part I, Experiment classtime, Tuesday, Nov 6 th, 2018.

CS 209 Section 52 Lab 1-A: Getting Started with NetBeans Instructor: J.G. Neal Objectives: Lab Instructions: Log in Create folder CS209

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

CS111: PROGRAMMING LANGUAGE II

Event Driven Programming

CS 209 Programming in Java #10 Exception Handling

To gain experience using GUI components and listeners.

Contents Chapter 1 Introduction to Programming and the Java Language

Java IDE Programming-I

CS Exam 1 Review Suggestions

CSE 1325 Project Description

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

DEMYSTIFYING PROGRAMMING: CHAPTER FOUR

SINGLE EVENT HANDLING

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Critical Thinking Assignment #6: Java Program #6 of 6 (70 Points)

CS111: PROGRAMMING LANGUAGE II

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

Agenda. Container and Component

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

CS 134 Programming Exercise 7:

GUI Forms and Events, Part II

CS 209 Spring, 2006 Lab 12: JAR Files Instructor: J.G. Neal

CSC 161 SPRING 17 LAB 2-1 BORDERLAYOUT, GRIDLAYOUT, AND EVENT HANDLING

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Java Programming Lecture 6

AP CS Unit 11: Graphics and Events

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Project 3. For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports.

Chapter 6: Graphical User Interfaces

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Review sheet for Final Exam (List of objectives for this course)

Final Examination Semester 2 / Year 2010

Java Programming Lecture 7

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

We are on the GUI fast track path

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Programming graphics

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

CS180 Recitation. More about Objects and Methods

Week Chapter Assignment SD Technology Standards. 1,2, Review Knowledge Check JP3.1. Program 5.1. Program 5.1. Program 5.2. Program 5.2. Program 5.

Window Interfaces Using Swing Objects

Graphical User Interface (GUI)

1005ICT Object Oriented Programming Lecture Notes

Yanbu University College Applied Computer Science (ACS) Introduction to Computer Science (CS 102) Lab Exercise 10

Graphical User Interfaces. Comp 152

Part I: Learn Common Graphics Components

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

2IS45 Programming

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

Window Interfaces Using Swing. Chapter 12

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Chapter 12 Advanced GUIs and Graphics

Chapter 17 Creating User Interfaces

Initial Coding Guidelines

Graphics User Defined Forms, Part I

Window Interfaces Using Swing Objects

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

Class 16: The Swing Event Model

Java Just in Time: Collected concepts after chapter 22

Swing/GUI Cheat Sheet

Lab 10: Inheritance (I)

EVENTS, EVENT SOURCES AND LISTENERS

CS 251 Intermediate Programming GUIs: Event Listeners

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

GUI Components Continued EECS 448

Contents Introduction 1

PIC 20A GUI with swing

Index SELF-STUDY. Symbols

Here are the steps to get the files for this project after logging in on acad/bill.

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

Enhanced Entity- Relationship Models (EER)

Java Event Handling -- 1

Final Examination Semester 3 / Year 2008

Final Examination Semester 2 / Year 2011

CMSC 150 Lab 8, Part II: Little PhotoShop of Horrors, Part Deux 10 Nov 2015

Jonathan Aldrich Charlie Garrod

Java Just in Time: Collected concepts after chapter 18

Graphical Applications

Graphical User Interfaces in Java - SWING

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

COMPSCI 230. Software Design and Construction. Swing

CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams

Chapter 13 Lab Advanced GUI Applications

Introduction to Object-Oriented Programming

Transcription:

CS 209 Spring, 2006 Lab 8: GUI Development Instructor: J.G. Neal Objectives: To gain experience with the programming of: 1. Graphical user interfaces (GUIs), 2. GUI components, and 3. Event handling (required for GUI programs). Notes: 1. This lab exercise correlates with Chapters 12 and 13 of the textbook. The most important sections are: 12.1-12.3 and 13.6-13.9. 2. You need to understand what an event is and when an event occurs. You need to understand what is meant by event handling. 3. In the Java code of a program, be sure that you know how to register an event listener object with the GUI control for which it is to await (listen for) events. You should be able to write the code to have a listener method react/respond to an event generated by its associated GUI component. 4. In this exercise, we are dealing with two types of events: a. ActionEvent: Generated by hitting the Enter key in a JTextField. So an ActionListener object must be registered with the JTextFields. The method addactionlistener is used to register a listener object with a JTextField. b. ItemEvent: Generated by selecting an item from a JComboBox (drop list). So an ItemListener object must be registered with the JComboBoxes. The method additemlistener is used to register a listener object with a JComboBox. Lab Instructions: 1. Obtain the Java files, named EmployeeAryApplicJF.java and EmployeeAryApplicJFMain.java, from instructor s webpage. 2. Create a NetBeans project for this assignment. Add the instructor-provided files to the project. The Java class/file EmployeeAryApplicJFMain.java must be used as the main class/file. The file EmployeeAryApplicJF.java implements a JFrame window. Add your employee classes to the project. That is, add your Employee, HourlyEmployee, SalariedEmployee, and UnionEmployee classes to the project. Be sure that your employee classes fulfill the requirements (meet the specifications) of the previous assignments. 3. Add required constructor to your existing classes. To run the initial program provided by your instructor, each of your four employee classes must have a constructor that takes two parameters: String nam, int idnumb. If your classes do not have such a constructor, add the constructor to each (do not delete any of the constructors that you already have in the classes, however). 4. Compile and run the program. After entering some employees, the JFrame window looks like the window shown below. The data displayed for each employee should include all the member variables, even though they are not yet being set by the current version of the program. (You will add capabilities to do this.) The displayed information on each subclass employee must be generated by the inherited tostring method of the parent Employee class. Page 1 of 7

5. Extend the program. Now you will modify and extend the program as described in the following steps. 6. Mod 1. Add components (controls) to the GUI. Change the GridLayout to accommodate the additional GUI components that you will add in the steps below. In the modifications described in the following steps, all JLabels must be in the left-side column of the GridLayout, and the JTextFields and JComboBoxes must be in the right-side column. Enable user entry of employee s job title: o Add another JLabel to prompt for the employee s job title. o Add another JComboBox to enable the user to select the job title for the employee. o At the top of the main class, create an array of job title names that consists of the following: Administrative Assistant, Clerk, Engineer, Manager, Quality Engineer, Salesperson, Secretary, Service Specialist, Software Engineer, and Technician. This array is similar to the array of employee types, which is declared as a variable at the top of the main class. Both are arrays of Strings. o You need to declare an additional variable at the top of the main class to hold the value selected by the user via the new JComboBox (just like for the employee type when the user selects employee type from the corresponding JComboBox). For this variable, use the name selectedjobtitle. This additional variable is declared so as to have class scope since it must be referenced/used in the listener class and in the methods of the EmployeeAryApplicJF class. Page 2 of 7

Enable user entry of employee s pay rate: o Add another JLabel to prompt for the employee s pay rate. o Add another JTextField to enable the user to input the employee s pay rate. Enable user entry of employee s hours worked: o Add another JLabel to prompt for the employee s hours worked. o Add another JTextField to enable the user to input the employee s hours worked. 7. Mod 2. Wire up your new GUI components (controls) to event handlers. Register an event listener (handler) with each of the new GUI controls so that when the user triggers an event via the use of a control, the event handler will react to the event and cause the correct action to be taken by the program. This applies to the new additional JTextFields and the new additional JComboBox. The next bullet items cover this further. This means that if the user hits the Enter key in any of the newly added JTextFields, this should cause the new employee to be added to the array and to have the entire updated list of employees displayed in the JTextArea, just like hitting the Enter key in one of the existing JTextFields. You will need to modify and extend the method actionperformed in the MyActionListener class. When the user selects from the new JComboBox, this should trigger the updating of the contents of the job title variable (selectedjobtitle) declared at the top of the class. You will need to modify and extend the method itemstatechanged method in the MyItemListener class to accomplish the above. Be sure that the contents of all the JTextFields are cleared when the user hits the Enter key to trigger creation of the new additional employee. 8. Mod 3. In the addemployeetoarray method, modify the creation of employee instances. Depending on the type of employee selected by the user via the JComboBox (drop list), the program must create an instance of the correct employee subclass (HourlyEmployee, SalariedEmployee, or UnionEmployee), as it currently does. Your program must not create any instances of the top level Employee class. You must add parameters to the formal parameter list of the addemployeetoarray method. You must add parameters for: job title, pay rate, hours worked. When creating the employee instance, the code of this method must call the constructor in the correct subclass and pass the following parameters: name, id number, job title, pay rate, and hours worked. (You need to add this constructor in each class.) Do not pass employee type as a parameter. It is not necessary. Each class should initialize the employeetype variable without passing a parameter. Each class should know its type without passing a parameter. 9. Mod 4. Modify the call to the addemployeetoarray method. In the call to the addemployeetoarray method, add the actual parameters for job title, pay rate, hours worked. The total parameter list must consist of only the following items: name, id number, job title, pay rate, and hours worked. Page 3 of 7

10. Mod 4. Modify your employee classes. In each of your employee classes, add a constructor that has a parameter list that consists of a parameter for each of the following, and only the following: name, id number, job title, pay rate, and hours worked (as mentioned above). The constructor in the correct class with the above-mentioned parameter list must be called whenever an employee instance is created in your program. As stated in the above numbered step, do not pass employee type as a parameter. It is not necessary. Each class should initialize the employeetype variable without passing a parameter. Each class should know its type without passing a parameter Modify your employee classes so that the code is optimal. This means, for example, that you only add jobtitle as a protected variable in the parent Employee class and have the subclasses inherit this member variable. You should not add the job title as a member variable in any of the employee subclasses. No member variables should be declared in any of the subclasses. To clarify: the HourlyEmployee, SalariedEmployee, and UnionEmployee classes must only contain constructors and a computepay method, and nothing else. These three subclasses must not have a tostring method. You must have a tostring method in the top level Employee class, but not in any of the subclasses (not in the HourlyEmployee, SalariedEmployee, or UnionEmployee classes). Your Employee class must have a tostring method, but be sure that none of the other employee classes have a tostring method. Make sure that the tostring method returns a string that includes all of the following information items: employee s name, id number, employee type, job title, pay rate, hours worked, and computed pay. Be sure that the computepay method is called by the tostring method. The tostring method must not contain any math expressions that calculate pay. Furthermore, none of the classes should have logic that selects a compute pay method or formula based on whether hourly, salaried, or union. The employee type should not be passed as parameter to any of the constructors or methods in any of the employee classes or subclasses. Also, none of the classes or methods should have logic that selects an employee type or type name based on whether hourly, salaried, or union (or any representation of these such as ints or chars). Make sure that in the tostring method, all monetary amounts are formatted with a dollar sign and two digits to the right of the decimal point (as in previous exercises). Make sure that in the tostring method, the employee s hours worked value is formatted with two digits to the right of the decimal point (as in previous exercises). 11. Mod 5. Modify the code for the first JLabel for No. of Employees. Modify the code for this JLabel so that the maximum number of allowed employees is displayed in place of the question marks. The code must use the variable name for the max size of the array, and not the actual literal number. The use of the variable name is for maintainability. The literal should be in one place only. 12. Mod 6. Modify the Titled Border and contents of the JTextArea. Page 4 of 7

Change the text of the TitledBorder of the JTextArea to read XYZ Corporation Employees. Eliminate the line of text XYZ CORPORATION EMPLOYEES: from the text displayed within the JTextArea. The contents of the JTextArea should just be the list of employees with all attributes displayed for each employee. For each employee, display the employee s name, id number, employee type, job title, pay rate, hours worked, and computed pay. Make sure that all monetary amounts are formatted with a dollar sign and two digits to the right of the decimal point (as in previous exercises). This is done by the tostring method (see Item 10 above). Make sure that the employee s hours worked is formatted with two digits to the right of the decimal point (as in previous exercises). This is done by the tostring method (see Item 10 above). 13. Compile, execute, and debug the program. Test your program using a sufficient variety of data to make sure that it works on all cases. 14. Run the program and make window captures displaying all the capabilities of your program. See the window captures below for example program input/output displays. 15. Create batch file. Create a batch file as you did for the previous assignments so that your program can be executed without the use of NetBeans. Be sure that the batch file is within your top level NetBeans project folder. 16. Create ReadMe file. Using Microsoft Word, create a file named ReadMe. In this document, insert your name at the top, and on the next line insert the assignment number (e.g., Exercise #8 ). Then enter any comments regarding the assignment. Your comments might include any difficulties encountered, suggestions for improvement of the assignment, etc. Then insert at least two window captures of your JFrame window showing the inputs and outputs from the execution of the program. o The first window capture should be captured when you have entered data on the 4 th employee; it should show the data in the JTextFields and selected items in the JComboBoxes. o The second window capture should show the updated list of employees in the JTextArea that is the result of hitting the Enter key in one of the JTextFields for this new 4 th employee. If you did the extra credit part of the assignment, be sure to state this in your ReadMe file. (The extra credit portion of the exercise is specified below.) Also, include additional window captures that demonstrate the execution of the extra credit version of your program and its extra capabilities. Be sure the ReadMe document file is in your top level project folder. 17. Zip the project folder and all its contents. Create a zip file that contains the entire contents of your NetBeans project folder, including all sub-folders and files. Page 5 of 7

Your project folder should contain your ReadMe file and batch file, as for previous project assignments. Change the name the zip file so that its name consists of your name along with the assignment number, as follows: JohnJones-08.zip. Do not use spaces in the name of the file, use hyphens instead. 18. Extra Credit: In the main class for your project, in the constructor, add a JScrollPane to the GUI to hold the JTextArea. In order to accomplish this, do the following: Create an instance of the JScrollPane class. When invoking the JScrollPane constructor, pass the JTextArea as a parameter to the constructor so that the JTextArea is the component on the JScrollPane (the JScrollPane holds the JTextArea as its content). Add the JScrollPane to the JPanel instead of adding the JTextArea to the JPanel. The above addition of the JScrollPane should provide vertical scroll bars automatically when needed. For example, do not resize the main JFrame window. Then, after entering 4 employees, you will need to scroll vertically to see the data on some of the employees, since the JTextArea is only large enough to display the data on 4 employees. If you need more information, consult the Java 5.0 Documentation on the Java 2 Platform API Specification. TO RECEIVE CREDIT FOR YOUR ASSIGNMENT: Submit the following for credit to Angel Drop Box for Exercise 08: a. The zip file containing your entire NetBeans project folder with all its subfolders and files. b. You must have a batch file to run your program without using NetBeans, and the batch file must be in your top level project folder. c. You must have a ReadMe file that contains your name at the top, the lab number, any comments regarding the assignment, and window captures to show the program execution. The ReadMe file must be in the top level project folder. d. You must submit your zip file to the Lab08 Drop Box for this CS 209 course in Angel (http://angel.ecc.edu). DUE DATE: Tuesday, March 28. EXAMPLE WINDOW CAPTURES FOR THE COMPLETED PROGRAM: See next page. The windows show the extra credit JScrollPane also. Page 6 of 7

Page 7 of 7