Java-GUI-Spr04

Java-GUI-Spr04 - GUI and Event-Driven Programming COP 3330...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
GUI and Event-Driven Programming COP 3330 © Rong Wang School of Computer Science Febuary 2004 Revised April, 2004 Slides developed based on Java Programming Design By James P. Cohoon and Jack W. Davidson, McGrawHill, 2004 and Mark Llewellyn’s slides on COP3330 fall 2003
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 GUI and Event-Driven Programming Most users of software prefer a graphical user-interface ( GUI ) -based program over a console-based (command-line based) program. Studies have found that users find GUIs easier to manipulate and more forgiving when misused (that is, if they are well designed ). A GUI’s ease of use comes at a programming price – GUI-based programs are more complex in their structure than console-based programs.
Background image of page 2
3 A First GUI Our first example of a GUI will be a program that calculates the windchill temperature for a user-specified temperature and windspeed. Windchill is the temperature perceived by a person when taking into account the actual air temperature and the speed of the wind. It is similar to a more popular term in Florida which is the heatindex that considers the actual air temperature and the humidity. You can use the GUI we develop this winter when you go skiing (not in Florida, of course). There are several different formulas available for calculating windchill. The one in our program is used by the U.S. National Weather Service and is only valid for windspeeds in excess of 4 mph.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 What the GUI Should Look Like
Background image of page 4
5 Components of the GUI Compared to a console-based application program, a GUI has many more objects to consider. A GUI program also has to deal with the interactions of its graphical components. For example, whenever a user clicks the windchill calculator run button, the button dispatches a signal. The GUI must have a listener for that signal that causes the current temperature and windspeed data entry values to be obtained, the windchill to be calculated, and the result of that computation to be assigned to the windchill temperature entry area.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Components of the GUI (cont.) Java GUI-based programming typically makes use of the swing API . The swing API provides over 40 different types of graphical components and 250 classes to support the use of these components. In creating a GUI, the following swing classes are particularly useful: JFrame: Represents a titled, bordered window. JTextArea: Represents an editable multi-line text entry component. JLabel: Represents a display area suitable for one or both of a single-line text or graphic image. JTextField: Represents an editable single-line text entry component. JButton: Represents a push button.
Background image of page 6
Swing API Classes in the WindChill Window Title bar of JFrame instance. The JFrame contains 8 GUI
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 70

Java-GUI-Spr04 - GUI and Event-Driven Programming COP 3330...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online