Intro to Graphical User Interfaces
Download
Report
Transcript Intro to Graphical User Interfaces
Graphical User Interfaces
SE-1020
Dr. Mark L. Hornick
1
You’ve already done some Java
GUI programming
JOptionPane - a multi-purpose class whose
behavior varies based on which static method
you invoke
showMessageDialog
showInputDialog
showConfirmDialog
showOptionDialog
SE-1020
Dr. Mark L. Hornick
2
JOptionPane. showMessageDialog()
provides a simple way to display a
message to the user:
JOptionPane.showMessageDialog(null, “I Love Java”);
SE-1020
Dr. Mark L. Hornick
3
JOptionPane. showInputDialog() provides
a way to prompt the user for some text
input:
String text =
JOptionPane.showInputDialog(null,
"Enter some text:", "Input dialog",
JOptionPane.QUESTION_MESSAGE);
SE-1020
Dr. Mark L. Hornick
4
JOptionPane.showConfirmDialog()
provides a way to present a variety of
standard button choices to the user:
response = JOptionPane.showConfirmDialog( null,
"Run Again?", "Confirmation",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE );
SE-1020
Dr. Mark L. Hornick
5
JOptionPane.showOptionDialog() provides
A way to customize the options presented
to the user beyond the standard choices:
Object[] options = { “Bye" };
JOptionPane.showOptionDialog(null,
"Game over; you're broke.",
"Please come again", JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
SE-1020
Dr. Mark L. Hornick
6
There are a lot more GUI classes than
just JOptionPane
These are in two different packages
AWT (Abstract Window Toolkit) classes are
implemented by using the native GUI objects
AWT classes for Windows are written differently than AWT
classes written for the MAC
A GUI application written on for a MAC will look different than
one written for a Windows-based PC
Swing classes are fully implemented in Java, and
behave the same on different operating systems.
They provide greater compatibility across different operating
systems
(JOptionPane is part of javax.swing)
SE-1020
Dr. Mark L. Hornick
7
Swing classes support many more
functionalities not supported by AWT
counterparts
Rules for usage:
Do not mix the counterparts (e.g. AWT buttons and Swing
buttons) in the same program because of their differences in
implementation.
UNLESS there is no Swing counterpart to AWT (e.g. AWT
Graphics)
then it is OK to use AWT.
SE-1020
Dr. Mark L. Hornick
8
The JFrame class is the fundamental
“window” class
It contains rudimentary functionalities to support features found in any frame
window.
A JFrame object serves as the “host” for containing other components,
JTextField
JLabel
JFrame
JButton
SE-1020
Dr. Mark L. Hornick
9