NATIONAL UNIVERSITY OF SINGAPORE
School
of Computing
CS3283
: GUI Programming –
Open-book
Mid-term on GUI Basics, Swing and Tcl/Tk(10%)
(Semester
II, 2001)
Date : Mar 16 (Friday Lecture) Time Allowed : 45 min.
This mid-term consists of 8
multiple-choice questions and TWO short questions printed on 5 pages. The
questions are NOT ordered in increasing order of difficulty NOR sequential
order of topics covered. You have to submit your clearly written answers printed on these question sheets ONLY. Make
sure you fill in your full name and matric. no. before submission.
Full Name : ______________________________________________
Matriculation Number : ______________________________________________
Total
Marks : = ____________
(1)
What
class controls the order in which components are drawn in their top-level
container?
(a)
JFrame
(b)
JContainer
(c)
JRootPane
(d)
JLayeredPane
(e)
None of the
above
ans : _______d______________
(2)
What
does the following code do?
JButton enterButton = new
JButton("Enter");
layeredPane.add(enterButton,
LayeredPane.Default_Layer, 0);
(a)
Adds a
JButton to the default layer and specifies that it appears behind all
heavyweight components in that same layer.
(b)
Adds a
JButton to the default layer and specifies that it appears behind the other
components in that same layer.
(c)
Adds a JButton to the default layer and
specifies that it appears on top of the drag-and-drop layer.
(d)
Adds a
JButton to the default layer and specifies that it appears in front of the
other components in that same layer.
(e)
none of the
above.
ans : _________d____________
(3) What do you need to do to
implement a custom table model?
(a)
Implement a method to return the number of rows and another one to
return the number of columns.
(b)
Implement a method to retrieve an element at a specific location.
(c)
Extend AbstractTableModel or DefaultTableModel.
(d)
All of the above.
(e)
None of the above.
ans : __________d___________
(4)
Which
of the following observation(s) is/are valid for Tcl and Tk ?
(a)
Tcl is a
general-purpose scripting language for building GUIs.
(b)
Tk is a
general-purpose scripting language for controlling robots or machines to fulfil
various tasks.
(c)
Tk is a
special-purpose package sitting inside the Tcl framework.
(d)
Tcl has
been recently extended as Tcl-e-Comm for building e-Commerce applications.
(e)
none of the
above.
ans : _________c____________
(5) What are the two general
categories of classes in the Swing library ?
(a)
Event and
model classes
(b)
AWT and
Swing classes
(c)
UI and
non-UI classes
(d)
Event and
view classes
(e)
Data and
action classes
ans : ______c_______________
(6) Which of the following
observations(s) is/are valid about Swing components?
(a)
When a
lightweight and heavyweight component overlap, the lightweight component is always
on top.
(b)
A lightweight component can only be
rectangular.
(c)
A mouse
event on a heavyweight component falls through to its parent.
(d)
A
lightweight component can have transparent pixels, and a heavyweight
component is always opaque.
ans : __________d___________
(7) Which methods in the
SwingUtilities class give you some control over the event queue?
(a)
addEventListener()
and setEventTypeListener()
(b)
isEventDispatchThread()
(c)
invokeLater()
and invokeAndWait()
(d)
notifyAction()
(e)
getUIActionMap
ans : ______c____________
(8) Which of the following
observation(s) is/are true about invoking Tk ?
(a)
Tk supports
by defaults 3 modes for invocation : interactive mode, non-interactive mode,
and a combination of both modes.
(b)
We can
invoke “tclsh” and key in the Tk commands interactively.
(c)
Interactive
mode for Tk simply means changing the mode of a script file to be executable on
Unix/DOS, then execute it interactively.
(d)
The “wish”
shell is to support interactive execution of Tk commands.
(e)
The “wish”
shell is to support interactive mode for Tcl commands and non-interactive mode
for Tk commands.
ans : ______d____________
B.
Short Questions (6%)
(1) a. Show the code that creates a label displaying
the following text, with the italics and boldface as shown in this screenshot
(1.5%):
Ans:
label =
new JLabel("<html>The <em>last</em> word is
<b>bold</b>.");
(1.5%)
b. Assume that you have a Swing label that tends to
have more horizontal space than it needs to display its text. What code would
you use to make the text within a label (JLabel) be centered instead of
left-aligned?
Ans :
Here are two ways:
new JLabel(labelText, JLabel.CENTER);
or
label.setHorizontalAlignment(JLabel.CENTER); (1.5%)
(2) (3%)
Tcl has C-like syntax. In the following table, there are some simple C
assignment statements translated into Tcl commands. Fill in the expected value
for each variable after executing the Tcl command.
C
Statement |
Result |
Tcl
Command |
Result |
A =
12; |
a = 12 |
set a
12 |
a = 12
(0.5%) |
X =
(3<4); |
x = 1 |
set x
(3<4) |
x =
(3<4) (0.5%) |
Besides, for EACH of the above
cases, explain clearly why Tcl has the
"same" or "different"
result as C.
Explanation :
1st case - both have "same" result
since C stores (integer) 12 into var. a. Similarly, Tcl assigns/substitutes
(string) 12 into a. (1%)
2nd case - both have different result since C directly
evaluates the boolean expr. (3 < 4) and store the result into var. x.
However, Tcl simply takes (3 < 4) as string and substitutes into x during
parsing. (1%)
-------------END OF PAPER-------------