GUI Basics

Topics: HTML, HTML element, Typography Pages: 57 (6437 words) Published: September 30, 2014

Chapter 12 GUI Basics
12.1 Swing components that don't rely on native GUI are referred to as ___________. A. lightweight components
12.2 __________ are referred to as heavyweight components. A. AWT components
12.3 Which of the following statements are true?
A. To distinguish new Swing component classes from their AWT counterparts, Swing GUI component classes are named with a prefix J. B. All Swing GUI components are lightweight.
C. A user interface object such as (button, list) can appear in one container. The correct answer is ACD
Explanation: (B) is false, because only the Swing components that don?t rely on native GUI are lightweight. Some Swing GUI components such as JFrame are heavyweight. (E) is false. For example, a JFrame cannot be added to a container, because it is a top-level container. 12.4 Which of the following classes is a heavyweight component? D. JFrame

12.5 Which component cannot be added to a container?
C. JFrame
12.6 Which of the following are subclasses of java.awt.Component? A. Container classes
B. Swing user interface classes
12.7 What is best to describe the relationship between a container and a SWing GUI object in the container? C. Composition
12.8 What is best to describe the relationship between a container and a layout manager? B. Aggregation

12.9 What is best to describe the relationship between JComponent and JButton? D. Inheritance
12.10 What is best to describe the relationship between Component and Color? A. Association

12.11 What is best to describe the relationship between Component and Font? A. Association
12.12 Which of the following classes are in the java.awt package? A. Color
B. Font
C. Component
The correct answer is ABC
12.13 Analyze the following code.

import java.awt.*;
import javax.swing.*;

public class Test {
public static void main(String[] args) {
Component c = new JButton("OK");
JFrame frame = new JFrame("My Frame");
frame.add(c);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

C. You cannot add a Swing component directly to a JFrame using add(c) prior to JDK 1.4, but it is OK in JDK 1.5.

12.14 The correct order of the following three statements is ___________.

1. frame.setLocationRelativeTo(null);
2. frame.setSize(100, 200);
3. frame.setVisible(true);

C. 2 1 3
Explanation: setSize method should be invoked before invoking setLocationRelativeTo(null). Mistakes are made in the 6E book. Thanks to Elnur from Russia for the correction.

12.15 Analyze the following code.

import java.awt.*;
import javax.swing.*;

public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new JButton("OK"));
frame.add(new JButton("Cancel"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
B. Only button Cancel is displayed.

12.16 How many frames are displayed?

import javax.swing.*;

public class Test {
public static void main(String[] args) {
JFrame f1 = new JFrame("My Frame");
JFrame f2 = f1;
JFrame f3 = f2;
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
}
}
A. 1.

12.17 How many frames are displayed?
import javax.swing.*;
public class Test extends JFrame {
public static void main(String[] args) {
JFrame f1 = new Test();
JFrame f2 = new Test();
JFrame f3 = new Test();
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
}
}

C. 3

12.18 Which of the following statements is for terminating the program when closing the frame? A. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

12.19 Which of the following statements is for placing the frame's upper left corner to (200, 100)? C. frame.setLocation(200, 100)

12.20 Analyze...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • The Basics for Writing Undergraduate History Essays and Papers
  • Essay about Lesson Plan Visual Basic
  • The Basic Research Paper Format
  • Gough’s Definition of Needs and His Different Categories for Basic Human Needs Essay
  • Visual Basic 6.0 Essay
  • Essay on Learning Visual Basic
  • Essay about Basic Instinct
  • Essay about Graphical User Interface and Visual Basic

Become a StudyMode Member

Sign Up - It's Free