Lab 8 - Graphical User Interface (GUI) With Event Handling (Select, Click, Short Key)
Lab 8 - Graphical User Interface (GUI) With Event Handling (Select, Click, Short Key)
Lab-08
Graphical User Interface (GUI) with Event Handling (Select, Click, Short Key)
Lab 08: Graphical User Interface (GUI) with Event Handling (Select, Click, Short Key)
Table of Contents
1. Introduction 91
4. Concept Map 91
4.1 List Selection Listener 91
4.2 Mouse Event Handling 92
6 Procedure& Tools 93
6.1 Tools 93
6.2 Setting-Up IDE [Expected time = 10mins] 93
6.2.1 Download NetBeans 93
6.2.2 Install NetBeans 93
6.3 Walkthrough Task [Expected time = 50mins] 93
7 Practice Tasks 96
7.1 Practice Task 1 [Expected time = 20mins] 96
7.2 Practice Task 2 [Expected time = 20mins] 96
7.3 Bonus Practice Task [Expected time = 1 day] 97
7.4 Out comes 97
7.5 Testing 97
9 Evaluation criteria 98
10 Further Reading 99
10.1 Books 99
10.2 Slides 99
1. Introduction
Graphical user interface and its importance is describing in previous lab. In this lab will discuss
about the Event Handling of GUI like Select, Click, and Short Key. Using the previous lab
knowledge will get the basic understanding of event handling of GUI.
4. Concept Map
In these two examples, you can dynamically change the selection mode to any of the three
supported modes:
single selection mode
single interval selection mode
multiple interval selection mode
After reading the reference material mentioned in the introduction, now you are ready to perform
homework assigned to you.
Develop the understanding of all the packages used in AWT and Swing.
Explore different types of event handling techniques with code
5.2.1 Task-1
Your task is to create a basic interface of small calculator, Insert a JFRAME Container and insert
3 textfields each with its label “First Number”, “Second Number”, “Results” respectively.Result
text field should be non-editable.Now insert 4 jbuttons “Multiply”, “Divide”, “Add”, “Substract”
each will the source of its event handler and perform a specified operation. And will show the
result in result text field. Add short key, Mouse event handler in this task.
6 Procedure& Tools
In this section you will study how to create an event driven program using NetBeans IDE.
6.1 Tools
Go to the following link to download latest version of NetBeans IDE with Java SE
support.http://www.oracle.com/technetwork/java/javase/downloads/jdk-7-netbeans-download-
432126.html
Install the downloaded NetBeans in your desired location then follow directions given in the next
section.
In last lab you learn about the usage of NetBeans. Create project GUIEventHandling and add
JFrame Rename the JFrame with ShortCutKey.java. Add Menu bar in JFrame as shown in
Figure 1
After adding the menu item change the properties of menu item and add the short cut key for performing action.
Shown in figure 4
Figure 7: Output
7 Practice Tasks
This section will provide more practice exercises which you need to finish during the lab. You
need to finish the tasks in the required time. When you finish them, put these tasks in the
following folder:
\\dataserver\assignments$\Advanced Computer Programming\Lab13
Develop them through text file first and then IDE. (NetBeans or Eclipse)
Create a Java interface using a jframe and four components on top of that frame, with title
“Yellow”, “Blue”, “Green”, “Gray” when user click on any button, the frame background color
as well as of that button’s should change accordingly.Frame’s title should be COLORS.
Female Ideal Weight = Height2 /30, Male Ideal Weight = Height2 /28
Insert a main Jframe and two radio buttons for Male & Female Selection, and 5 Radio buttons
with labels with the range from 60 to 80 inches split each range with the difference of 4 and pick
the middle value. Also sets the default values of radio buttons.
Insert the Ideal weight text field, when user will change the selected radio button, it will update
the ideal weight read only text field. Your weight calculator should look something like the form
After completing this lab, student will be able to understand the usage IDE in developing event
driven applications.
7.5 Testing
This section provides you the test cases to test the working of your program. If you get the
desired mentioned outputs for the given set of inputs then your program is right.
Click on the buttons and check if the background colors change accordingly or not.
Input Output
Click on Green Button
Select different options from Gender and Height and check if the ideal weight value is according
to the formula
The lab instructor will give you unseen task depending upon the progress of the class.
9 Evaluation criteria
The evaluation criteria for this lab will be based on the completion of the following tasks. Each
task is assigned the marks percentage which will be evaluated by the instructor in the lab whether
the student has finished the complete/partial task(s).
10 Further Reading
10.1 Books
Text Book:
Java: How to Program by Paul J. Deitel, Harvey M. Deitel. Eighth Edition
Java Beginners Guide: http://www.oracle.com/events/global/en/java-outreach/resources/java-a-
beginners-guide-1720064.pdf
http://exampledepot.8waytrips.com/ for the package by package examples
10.2 Slides
The slides and reading material can be accessed from the folder of the class instructor available
at \\dataserver\jinnah$\