CIS016-1 - Principles of Programming: Week 6
CIS016-1 - Principles of Programming: Week 6
Programming
Week 6
15/05/21
1
Agenda
GUI Examples
2 15/05/21
Swing and AWT, Simple Input
4 15/05/21
Warming up: A Simple Input Dialog
String aString =
JOptionPane.showInputDialog(“Please enter
something”);
5 15/05/21
GUI Introduction
7 15/05/21
Copyright © 2008 Pearson Addison-Wesley. All rights reserved
EVENT-DRIVEN
PROGRAMMING AND GUIS
8 15/05/21
Events and Event-driven Programming
11 15/05/21
Event Handlers
12 15/05/21
Event Firing and Event Listening
14 15/05/21
Event-driven Programming vs
Sequential Execution
15 15/05/21
Event-driven Programming
16 15/05/21
GUIS WITH JAVA SWING AND
JFRAME
17 15/05/21
A Simple Window
18 15/05/21
A Simple Window
19 15/05/21
A First Swing Demonstration
24 15/05/21
Close-Window Button
The following line from the FirstSwingDemo program ensures that
when the user clicks the close-window button, nothing happens
firstWindow.setDefaultCloseOperation( J
Frame.DO_NOTHING_ON_CLOSE);
Note that the close-window and the other two accompanying buttons
are part of the JFrame object, and not separate buttons
25 15/05/21
GUI Components - JFrame
26 15/05/21
GUI Components – JButton,
Container
The Jbutton class is a GUI component that can be
placed directly in a Jframe or in a Container
(ContentPane).
A Container or ContentPane holds components of a
JFrame object
It can contain different layouts
It also needs to be imported from javax.swing.*;
27 15/05/21
JButton and Events
28 15/05/21
GUI Example – Simple GUI
See FirstSwingDemo
29 15/05/21
GUI Components -
JTextArea
30 15/05/21
GUI Components – Event Handling
31 15/05/21
GUI Components – Event Handling
33 15/05/21
GUI Components – Event Handling
See NextGUI
34 15/05/21
GUI Components – JLabel
If we want to just display some text (similar
to System.out.print), we can use
JLabel
35 15/05/21
GUI Components – Layout Manager
36 15/05/21
Grid Layout and Container
Example
con
GridLayout(2,1) colourPanel
GridLayout(1,2)
textPanel
GridLayout(2,3)
37 15/05/21
To Take Home
Event-based Programming
38 15/05/21
Further Reading
39 15/05/21