Lesson 5.2: Graphical User Interface Design Flashcards

1
Q

Why are the AWT components referred to as heavyweight?

A

The AWT defines a basic set of components that support a usable، but limited، graphical interface. One reason for the limited nature of the AWT is that it translates its various visual components into their corresponding، platform-specific equivalents، or peers. This means that the look and feel of an AWT component is defined by the platform، not by Java. Because the AWT components use native code resources، they are referred to as heavyweight.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What were the three main problems in the use of native peers in the AWT environment?

A

The use of native peers led to several problems. First، because of differences between operating systems، a component might look، or even act، differently on different platforms. This potential variability threatened the overarching philosophy of Java: write once، run anywhere. Second، the look and feel of each component was fixed (because it is defined by the platform) and could not be (easily) changed. Third، the use of heavyweight components caused some frustrating restrictions. For example، a heavyweight component was always opaque.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When and how was swing introduced to java?

A

Not long after Java’s original release، it became apparent that the limitations and restrictions present in the AWT were sufficiently serious that a better approach was needed. The solution was Swing. Introduced in 1997، Swing was included as part of the Java Foundation Classes (JFC). Swing was initially available for use with Java 1.1 as a separate library. However، beginning with Java 1.2، Swing (and the rest of JFC) was fully integrated into Java.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does Swing address the limitations associated with the AWT’s components?

A

Swing addresses the limitations associated with the AWT’s components through the use of two key features: lightweight components and a pluggable look and feel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does it mean when we say that Swing has lightweight components?

A

With very few exceptions، Swing components are lightweight. This means that a component is written entirely in Java. They do not rely on platform-specific peers. Lightweight components have some important advantages، including efficiency and flexibility. Furthermore، because lightweight components do not translate into platform-specific peers، the look and feel of each component is determined by Swing، not by the underlying operating system. This means that each component can work in a consistent manner across all platforms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does MVC mean and what do its parts do individually?

A

Swing’s pluggable look and feel is made possible because Swing uses a modified version of the classic model-view-controller (MVC) architecture. In MVC terminology، the model corresponds to the state information associated with the component. For example، in the case of a check box، the model contains a field that indicates if the box is checked or unchecked. The view determines how the component is displayed on the screen، including any aspects of the view that are affected by the current state of the model. The controller determines how the component reacts to the user. For example، when the user clicks a check box، the controller reacts by changing the model to reflect the user’s choice (checked or unchecked). This then results in the view being updated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does Java implement its own version of MVC?

A

Although the MVC architecture and the principles behind it are conceptually sound، the high level of separation between the view and the controller was not beneficial for Swing components. Instead، Swing uses a modified version of MVC that combines the view and the controller into a single logical entity called the UI delegate. For this reason، Swing’s approach is called either the model-delegate architecture or the separable model architecture. Therefore، although Swing’s component architecture is based on MVC، it does not use a classical implementation of it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is are events in Java? What superclasses are they found in?

A

An event is an object that describes a state change in an event source. It can be generated as a consequence of a person interacting with an element in a graphical user interface or generated under program control. For example، an event is generated when the user clicks a button، moves the mouse، types a key، or selects an item from a list. Events can also be generated in other ways. The superclass for all events is java.util.EventObject. Many events are declared in java.awt.event. Events specifically related to Swing are found in javax.swing.event.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does the event handling mechanism work، what is it called، and what are its advantages?

A

The event handling mechanism used by Swing is called the delegation event model. Its concept is quite simple. An event source generates an event and sends it to one or more listeners. With this approach، the listener simply waits until it receives an event. Once an event arrives، the listener processes the event and then returns. The advantage of this design is that the application logic that processes events is cleanly separated from the user interface logic that generates the events. Therefore، a user interface element is able to “delegate” the handling of an event to a separate piece of code. In the delegation event model، a listener must register with a source in order to receive an event.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are source events and how do listeners interact with them? What is the general form of the code that is used to register a listener to an event source?

A

An event source is an object that generates an event. When a source generates an event، it sends that event to all registered listeners. Therefore، in order for a listener to receive an event، it must register with the source of that event. In Swing، listeners register with a source by calling a method on the event source object. Each type of event has its own registration method. Typically، events use the following naming convention: public void addTypeListener(TypeListener el) Here، Type is the name of the event and el is a reference to the event listener. For example، the method that registers a keyboard event listener is called addKeyListener( ). The method that registers a mouse motion listener is called addMouseMotionListener( ). When an event occurs، the event is passed to all registered listeners.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In addition to registering a listener with an event source، what must you also do in that relationship? Think of what happens after the trigger of an event، what happens after that? What is the general form of this next action?

A

A source must also provide a method that allows a listener to unregister an interest in a specific type of event. In Swing، the naming convention of such a method is this: public void removeTypeListener(TypeListener el) Again، Type is the name of the event and el is a reference to the event listener. For example، to remove a keyboard listener، you would call removeKeyListener( ).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How fast should an event handler do its job، as a rule of thumb?

A

An event handler should do its job quickly and then return. In most cases، it should not engage in a long operation because doing so will slow down the entire application. If a time-consuming operation is required، then a separate thread should be created for this purpose.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the root of event class hierarchy? Where is the AWTEvent declared and what is it the super class of? Swing uses the AWT events but where are those events located?

A

At the root of the event class hierarchy is EventObject، which is in java.util. It is the superclass for all events in Java. The class AWTEvent، declared in the java.awt package، is a subclass of EventObject. It is the superclass (either directly or indirectly) of all AWT-based events used by the delegation event model. Although Swing uses the AWT events، it also adds several of its own. As mentioned، these are in javax.swing.event. Thus، Swing supports a large number of events. However، in this chapter only three are used. They are shown here، along with their corresponding listener.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What do the swing event classes ActionEvent، ItemEvent، and ListSelectionEvent do?

A

–Event Class / Description / Corresponding Event Listener -ActionEvent / Generated when an action occurs within a control، such as when a button is clicked. / ActionListener ItemEvent / Generated when an item is selected such as when a check box is clicked. / ItemListener ListSelectionEvent / Generated when a list selection changes. / ListSelectionListener

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Create result image using swing (A simple GUI box with two buttons inside it labled “Up” and “Down”).

A

ButtonDemo Program with Swing.png

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Create a text field example like this image result image (A text box that allows you to enter text، then has a button that reverses the text).

A

Use a text field.png

17
Q

Create an example of usable checkboxes in a GUI like this image result image (Allows you to select multiple of 3 check boxes and displays a text that tells you the one most recently selected).

A

Demonstrate check boxes.png

18
Q

Create an example program that displays the following JList GUI result image (A list of names and some text at the bottom telling you which one is currently selected).

A

Demonstrate a simple JList.png

19
Q

How do heavyweight containers differ from lightweight containers?

A

Heavyweight containers are implemented with native code and have the look and feel of the host system.

20
Q

What’s the role of the glass pane in Swing?

A

The glass pane covers the entire frame and is used to detect mouse events that apply to the entire area.

21
Q

Why does Swing not need an event handler to specify what to do when a window is closed?

A

Swing provides a method، setDefaultCloseOperation()، that specifies the action when a window is closed.

22
Q

Why should event handling in Swing be implemented on a separate thread?

A

Event handling must use a separate thread to ensure that the main thread is not blocked while events are being handled.

23
Q

The _______ pane is at the highest level of the Swing hierarchy.

A

JRootPane

24
Q

The layout manager that positions components at the top، bottom، left، right، or center positions is _______.

A

BorderLayout

25
Q

A Swing program that creates an instance of JButton must implement the _______ interface.

A

ActionListener