Upgrade to remove ads
Chapter 12 A first look at GUI applications
Terms in this set (49)
In java, you use the ____________-____________-_____________ to create a graphical user interface for your application. Within this, you use abstract windowing toolkit(AWT) or Swing classes to create graphical user interface.
Java Foundation classes
An area that can display text
an area in which the user may type a single line of input from the keyboard.
A component that displays a drop-down list of items from which the user may select. A combo box also provides a text field in which the user may type input. It is called combo box because it is a combination of a list and a text field.
A component that has a box that may be checked or unchecked
a list from which the user may check an item.
a component that can be either selected or deselected. Radio buttons usually appear in groups and allow the user to select one of several options
a component that allows the user to select a value by moving a slider along a track.
a button that can cause an action to occur when it is checked.
The Java Foundation Classes (JFC) consists of several sets of classes, many that are beyond the scope of what will be covered in this course. The ones that will be covered are:
AWT and Swing classes.
Swing applications can have the look of a specific operating system. The programmer may choose from a variety of "look and feel" themes.
Swing components can also be easily customized. The swing library provides many sophisticated components that are not found in the AWT.
Awt components are commonly called heavyweight components because they are coupled with their underlying peer classes. Very few of the swing components are coupled with peer classes, so are considered lightweight components.
Programs that operate in a GUI environment must be event-driven. An event is an action that takes place within a program, such as the clicking of a button. Part of writing a GUI application is creating event-listeners. An event listener is an object that automatically executes one of its methods when a specific event occurs. If you wish for an application to perform an operation when a particular event occurs, you must create an event listener object that responds when that event takes place.
The following statement will be used in every application that uses the swing classes:
The following statement will be used when an event, such as the clicking of a mouse, takes place in an application.
a container is simply a component that hold other components.
In GUI terminology, a container that can be displayed as a window is known as:
A _________ appears as a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing, and closing a window. In a Swing application, you create a frame object from the __________ class.
frame; JFRAME class
A label component is in the _______ class and is an area that can display text.
What Swing classes are the following components in? label, text field, button
Jlabel, JTextField, JButton
a_______ is a container that is part of every Jframe object
a_______ is also a container that can hold GUI components. Unlike JFrame objects, panels cannot be displayed by themselves; however they are commonly used to hold and organize collections of related components.
panel; With swing, you create panels with the JPanel class.
Don't forget that the letter x that appears after java in the Swing import statement: import javax.swing
Forgetting o specify the action taken when the user clicks on a JFrame's close button. By default, a window is hidden from view when the close button is clicked, but the application is not terminated. To do this, you must call the setDefault CloseOPeration method and pass JFrame.EXIT_ON_CLOSE as the argument.
Common error 3:
Forgetting to write an event listener for each event you wish an application to respond to. In order to respond to an event, you must write an event listener that implements the proper type of interface, registered to the component that generates the event.
Common error 4:
Forgetting to register an event listener. Even if you write an event listener, it will not execute unless it has been registered with the correct component.
Common error 5:
When writing an event listener method that is required by an interface, not using the method header specified by the interface. The header of an actionPerformed method must match that specified by the ActionListener interface. Also, the header of an itemStateChanged method must match that specified by the ItemListener Method.
Common Error 6:
Placing Components directly into the regions of a container governed by a BorderLayout manager when you do not want the components resized or yo want to add more than one component per region. If you do not want components that you place in a BorderLAyout region to be resized, place them in a Jpanel component and the add the JPanel component in the region.
Common Error 7:
Placing components directly into the cells of a container governed by GridLAyout manager when you do not want the components resized or you want to add more than one component per cell. If you do not want the components that you place in a GridLayout component to be resized, place them in a JPanel component, and then add the JPanel component to the cell.
Common Error 8:
Forgetting to add JRadioButton components to a ButtonGroup object. A mutually exclusive relationship is created between radio buttons only when they are added to a ButtonGroup object.
p.777: An ______________ is an action that takes place within a program, such as the clicking of a button. When this takes place, the component that is responsible for the ______ creates a _________ object in memory.
Event: Event: Event:
The event ____________ contains information about the event.
object; The component that generated the even object is known as the event source. For example, when the user clicks a button, the JButton component generates an event object. The JButton component that generated the event object is the event source.
A _____________ is an object that responds to events.
event listener; If the source component is connected to an event listener, then the event object is automatically passed, as an argument, to a specific method to the event listener. The method then performs any actions that it was programmed to perform in response to the event. This process is sometimes referred to event firing.
When you are writing a ___________________ application, it is your responsibility to write the classes for the event listeners that your application needs.
GUI application; For example, if you write an application with a jbutton component, an event will be generated each time the user clicks the button. Therefore, you should write an event listener class that can handle the event. In your application, you would create an instance of the event listener class and connect it to the JButton component.
Java allows you to write a class _________ inside of another class___________.
A class that is defined inside of another class is known as an___________ ____________.
There is a special requirement that all event listener classes must meet: They must ____________ an ___________.
You can think of an interface like a __________, containing one or more method headers.
class; Interfaces do not have actual methods, however, only their headers. When you write a class that implements an interface, you are agreeing that the class will have all of the methods that are specified in the interface.
Java provides numerous interfaces that you can use with event listener classes. There are several different types of events that can occur within a GUI application, and the specific interface that you use depends on the type of ___________ you want to handle
Jbutton components generate ____________ events, and an event listener class that can handle action events is also known as an _____________- ____________ class.
action; action listener. When you write an action listener class for a JButton component, it must implement an interface known as ActionListener.
The ActionListener interface, as well as other event listener interfaces, is in the java,awt,event package. The following is the import statement used to use those interfaces:
You use the __________ key word in a class header to indicate that it implements an interface.
Remember, when you write a class that implements an interface, you are "____________" that the class will have methods specified in the interface.
In your action listener class, the only part of the action performed methodheader that does not have to match what is shown in the actionlistener interface exactly is the name of the parameter variable. Instead of using the name e, you can use any legal variable name that you wish.
Registering an event listener object.
Once you have written an event listener class, you can create an object of that class, and then connect the object with a GUI component. The process of connecting an event listener object to a GUI component is known as REGISTERING the event listener; When a JButton component generates an event, it automatically executes the actionperformed method of the event listener object that is registered with it, passing the event object as an argument.
Many of the Swing component classes have methods named ______________ and _________________. You can call these methods to change a component's color.
setBackround and setForeground. The background is the color of the component itself, and the foreground color is the color of the text that might be displayed on the component.
Name the color constant color codes:
BLACK, CYAN, GRAY, LIGHT_GRAY, ORANGE, RED, YELLOW, BLUE, DARK_GRAY, GREEN, MAGENTA, PINK, WHITE
THIS SET IS OFTEN IN FOLDERS WITH...
Methods and Object Oriented in Java
Java, CH4-7 Unit 2 Big Java: Early Objec…
YOU MIGHT ALSO LIKE...
Java Ch12 First Look at GUI Applications
OTHER SETS BY THIS CREATOR
Chapter 10 Inheritance
Chapter 9 Notes
Java Key Words
OTHER QUIZLET SETS
Understanding the Earth's Interior via Earthquakes
Anatomy Exam 4
Biology final exam