




















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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Major points from this lecture are: Graphical User Interfaces, Interactive Programs, Gui Motivation, Environment, Gui Statics, Gui Dynamics, Dynamics, Components, Component Tree, Component Examples . Object-Oriented Programming and Data Structures course includes program structure and organization, object oriented programming, graphical user interfaces, algorithm analysis, recursion, data structures (lists, trees, stacks, queues, heaps, search trees, hash tables, graphs), simple graph algorithms
Typology: Lecture notes
1 / 28
This page cannot be seen from the preview
Don't miss anything!
-^ Program
-^ Statements
execute
in
sequential,
predetermined
order
-^ Typically
use
keyboard
or
file
but
program
determines
when
that
happens • Usually
single
‐threaded
-^ Event
-^ Program
waits
for
user
input
to
activate
certain
statements
-^ Typically
uses
a^
(Graphical
User
Interface) • Often
multi
‐threaded
-^
-^
-^
-^
-^ Classes
-^ Major
-^ awt
and
swing
-^ Pluggable
look
‐and
‐feel
support
-^ Accessibility
-^ Java
-^ Drag
‐and
‐drop
Support
-^ Internationalization
-^
-^
-^
-^
-^
-^
Why
Swing?
-^
-^
Statics:
what’s
drawn
on
the
screen •^ Components
-^ buttons,
labels,
lists,
sliders,
menus,
...
-^ Containers:
components
that
contain
other
components
-^ frames,
panels,
dialog
boxes,
...
-^ Layout
managers:
control
placement
and
sizing
of
components
Dynamics: user interactions •^
Events
-^
button
‐press,
mouse
‐click,
key
‐
press,
...
-^
Listeners:
an
object
that
responds
to
an
event
-^
Helper
classes
-^
Graphics,
Color,
Font,
FontMetrics,
Dimension,
...
import
javax.swing.;*
public
class
Basic
public
static
void
main(String[]
args)
//create
the
window
JFrame
f
new
JFrame("Basic
Test!");
//quit
Java
after
closing
the
window
f.setDefaultCloseOperation(JFrame.
f.setSize(200,
//set
size
in
pixels
f.setVisible(true);
//show
the
window
A
More
Extensive
Example
^
import
javax.swing.;*
^
import
java.awt.;*
^
import
java.awt.event.;*
^
public
class
Intro
extends
JFrame
{
^
private
int
count
=
0;
^
private
JButton
myButton
=^
new
JButton("Push
Me!");
^
private
JLabel
label
=
new
JLabel("Count:
"
+^
count);
^
public
Intro()
{
^
setDefaultCloseOperation(
EXIT_ON_CLOSE
);
^
setLayout(new
FlowLayout(FlowLayout.
LEFT
));
//set
layout
manager
^
add(myButton);
//add
components
^
add(label);
^
myButton.addActionListener(new
ActionListener()
{
^
public
void
actionPerformed(ActionEvent
e)
{
^
count++;
^
label.setText("Count:
"^
+^
count);
^
}
^
});
^
pack();
^
setVisible(true);
^
} ^
public
static
void
main(String[]
args)
{
^
try
{
^
UIManager.
setLookAndFeel
(UIManager.
getSystemLookAndFeelClassName
());
^
}^ catch
(Exception
exc)
{}
^
new
Intro();
^
} ^
}
-^
import javax.swing.;*
-^
import java.awt.;*
-^
public class ComponentExamples extends JFrame {
-^
public ComponentExamples() {
-^
setLayout(new FlowLayout(FlowLayout.
LEFT
));
-^
add(new JButton("Button"));
-^
add(new JLabel("Label"));
-^
add(new JComboBox(new String[] { "A", "B", "C" }));
-^
add(new JCheckBox("JCheckBox"));
-^
add(new JSlider(0, 100));
-^
add(new JColorChooser());
-^
setDefaultCloseOperation(
EXIT_ON_CLOSE
);
-^
pack();
-^
setVisible(true);
-^
}
-^
public static void main(String[] args) {
-^
try {
-^
UIManager.
setLookAndFeel
(UIManager.
getSystemLookAndFeelClassName
());
-^
} catch (Exception exc) {}
-^
new ComponentExamples();
-^
}
-^
}
Can
hold
other
components Has
a
layout
manager
A^
heavyweight
component
interacts
directly
with
the
host
system
JWindow,
JFrame,
and
JDialog
are
heavyweight
Except
for
these
top
‐level
containers,
Swing
components
are
almost
all
lightweight^
JPanel
is
lightweight
: top-level window with no
border JFrame
: top-level window with border
and (optional) menu bar JDialog
: used for dialog windows
: used mostly to organize
objects within other containers
JComboBox (mi)
JComboBox (km)
JTextField (2000)
JSlider
JTextField (3226)
JSlider