Lecture 15
Lecture 15
CSOO-122
Presented by
Dr. Muhammad Touseef Irshad
Lecture # 15
2
Graphical User Interface
5
Introduction to Swing in Java
Frame or Window
7
Sample Code (Frame)
8
Introduction to Swing in Java
9
Sample Code2 (Frame Icon)
Variable
Abstract Class of AWT
Static Method
Method Chain
10
Sample Code2 (Frame Icon)
11
Sample Code3 (Frame Background Colour)
12
Sample Code3 (Frame background Colour)
13
Introduction to Swing in Java
Button
▪ javax.swing.JButton
14
Sample Code1 (Button)
16
Sample Code2 (Button)
Manual placement
17
Introduction to Swing in Java
Label
18
Sample Code1 (Label)
19
Sample Code1 (Label)
20
Sample Code1 (Label)
21
Sample Code2 (Label)
22
Sample Code2 (Label)
23
Introduction to Swing in Java
Text Field
24
Sample Code1 (Text Field)
25
Sample Code1 (Text Field)
26
Introduction to Swing in Java
Text Area
27
Sample Code1 (Text Area)
28
Sample Code1 (Text Area)
29
Introduction to Swing in Java
Radio Button
30
Sample Code (Radio Button)
31
Sample Code (Radio Button)
32
Introduction to Swing in Java
Check Box
34
Sample Code (Check Box)
35
Introduction to Swing in Java
Menu
37
Sample Code (Menu)
38
Introduction to Swing in Java
Event Handling
i. Clicking a button
ii. Pressing a key
iii. Moving or clicking the mouse
iv. Closing a window
39
Introduction to Swing in Java
▪ Event Listener
▪ Event Action
40
Introduction to Swing in Java
41
Introduction to Swing in Java
42
Sample Code1 (Event Handling)
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.getContentPane().setBackground(Color.PINK);
}
}); This is a lambda expression e is the
event object
X,Y,W,H
43
Sample Code1 (Event)
44