

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: COMPUTER SCIENCE I; Subject: Computer Science and Engineering ; University: University of Nebraska - Lincoln; Term: Fall 2005;
Typology: Lab Reports
1 / 3
This page cannot be seen from the preview
Don't miss anything!


1. Lab Objectives Following the lab you should be able to: Describe the difference between an event-driven programming model and a traditional sequential programming model. Understand why event-driven programming is necessary and why it is used. Understand the underlying principles and the meaning of event listening. 2. Prior to the laboratory Review the laboratory handout. Read Wu, Chapter 7. Read the tutorial, “Event-Handling”, http://java.sun.com/docs/books/tutorial/uiswing/learn/index.html 3. Topics Topics Covered in Lab Event-driven programming Coordination of event handlers and listeners 4. Activities/Exercises Comparison of a sequential program with an event-driven program. Basic event-handling mechanisms. Creating a simple program to display a menu with options. [Extra Credit] Creating a combination lock. Activity 1: Comparison of a sequential program with an event-driven program Download SimpleDisplayName.java from the course website. Compile and execute SimpleDisplayName. Follow the instructions provided by the application. Complete Question 1 on your worksheet for Activity 1. Download DisplayName.java from the course website. Compile and execute DisplayName. Complete Question 2 on your worksheet for Activity 1. Study the DisplayName.java code to determine the portion of code where event-handling is performed. o Remove the comment markers in the portion of code where event-handling is performed, so that this code will also execute.
Activity 2: Basic event-handling mechanisms Download Calculate.java from the course website. Compile and execute Calculate.java. Part 1 – Change the “ADD” and “SUB“ buttons
o Modify the Calculate.java code so that the button labeled “ADD” will be displayed as “+“ and the button labeled “SUB” will be displayed as “ – “. (Hint: the program must still add the two numbers when the “+” button is pressed and subtract the two numbers when the “-” button is pressed.) o Modify the Calculate.java code so that the name of each button is representative of the button’s function by changing the object names. o Compile and execute the modified version of Calculate. o Test Calculate.java with a variety of inputs, including invalid inputs (enter non-numeric characters). o Complete Question 1 on your worksheet for Activity 2. Part 2 – Add new functionality to Calculate.java o Add a new button labeled “*”. o When the user clicks on the “ * “ button, the product of the two integers entered by the user is displayed in the “Result:“ text box. o Compile and execute the modified version of Calculate. Part 3 – Add new functionality to Calculate.java o Add a new button labeled “/”. o When the user clicks on the “/” button, the result of the first value divided by the second value is displayed in the “Result:” text box. o Enter a zero into the second input field and click on the divide key. Notice the error message in the JGrasp message window. o Add error checking to handle divide by 0 to avoid this runtime error. (Hint: do not do the calculation if the user enters a zero in the second field.) o Compile and execute the modified version of Calculate. Complete Question 2 on your worksheet for Activity 2. When you have implemented and tested the three parts of this activity, demonstrate your program for the lab instructor. Activity 3: Creating a simple program to display a menu with options Download JMenuFrame.java from the course website. Study the JMenuFrame.java code to determine what it does. Compile and execute JMenuFrame.java. Select each sub-menu from the menu-list and see what it does. Complete Question 1 on your worksheet for Activity 3. Modify the JMenuFrame program to add a new menu “Help”. Add two menu items to the Help menu: “Help Topics” and “About JMenuFrame”. When each menu item is selected, display a message that allows the user to know which menu item he or she has selected. Compile and execute the modified version of JMenuFrame. Complete Question 2 on your worksheet for Activity 3. Activity 4: [Extra Credit] Creating a combination lock Create a frame with 10 buttons, labeled 0 through 9. When the user clicks on the correct three buttons in order, the application displays a message indicating the combination entered is correct. When the user clicks on the three buttons in an order that does not match the combination, the application displays a message indicating the combination entered is incorrect. Add a “Quit” button that allows the user to exit the application. When you have implemented and tested the combination lock, demonstrate your program for the lab instructor.