Midterm Spring 2020
Midterm Spring 2020
Instructions:
1. Download the test on your computer, save, do your work, save again, and then upload through canvas.
3. Must submit through Canvas, on time. No email and late submission will be accepted
4. If any of your descriptive answer is similar to any other student both tests will be void
5. If any answer is a copy paste, the test will be void (write in your own words where necessary).
1. Applet runs inside browsers and can’t run as a client side. FALSE
2. Containers are special GUI components that hold and manage other components. TRUE
3. Radio buttons doesn’t need to operate as a group to provide a set of mutually exclusive options. FALSE
4. To implement the listener interface and override its methods are required to perform event handling.
TRUE
5. A GUI’s appearance is a function of the containment hierarchy and the layout managers of each container.
TRUE
6. SWING has more powerful components like tables, lists, scroll panes, color chooser, etc. FALSE
7. Applet is a java program that can be transported across a network and executed only by using a web
browser. TRUE
10. A listener may have to provide empty method definitions for unheeded events to satisfy the interface.
TRUE
Multiple Choice questions – there is only one correct answer for each question (2 points each):
A. The Canvas
B. Frame
C. Panel
This study source was downloaded by 100000853042928 from CourseHero.com on 03-12-2023 10:20:04 GMT -05:00
https://www.coursehero.com/file/74463433/midtermSpring2020docx/
D. All of the above - CORRECT ANSWER
2. Which of the following components may have a number of choices on the window?
B. Labels
C. List
D. Textarea
4. Which is the container that contains title bar and can have MenuBars as well as other components like
button, textField etc.
A. Window
C. Panel
D. Container
It is light weight
A. AWT
C. Both A & B
This study source was downloaded by 100000853042928 from CourseHero.com on 03-12-2023 10:20:04 GMT -05:00
https://www.coursehero.com/file/74463433/midtermSpring2020docx/
A. java.applet.Applet class
B. java.swing.JApplet class
C. java.awt.Panel class
7. 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?
A. new JLabel(labelText, JLabel.CENTER);
A.label.setHorizontalAlignment(JLabel.CENTER);
A. All of the above - CORRECT ANSWER
B. None of the above
A. Application runs explicitly within JVM whereas Applet loads and runs itself automatically in a java-en-
abled browser.
B. Application starts execution with its main method whereas applet starts execution with its init
method.
C. Application can run with or without graphical user interface whereas applet must run within a graphi-
cal user interface.
ANSWER:
This study source was downloaded by 100000853042928 from CourseHero.com on 03-12-2023 10:20:04 GMT -05:00
https://www.coursehero.com/file/74463433/midtermSpring2020docx/
1. Cannot load libraries or define native methods.
2. Cannot make network connections except to the host that it came from.
2. Write the code that implements the invokeAndWait() and invokeLater() method of Swing API (one line
code for each method). Explain in your own words the main difference between the two.
ANSWER:
SwingUtilities.invokeAndWait(runnable_name);
SwingUtilities.invokeLater(runnable_name);
3. Complete the following code to display an applet, so that the contents are contained in a rectangle around
the phrase "Exercise Applet". Use starting coordinates 5, 15 for the string.
g.drawRect(2,2,30,40);
This study source was downloaded by 100000853042928 from CourseHero.com on 03-12-2023 10:20:04 GMT -05:00
https://www.coursehero.com/file/74463433/midtermSpring2020docx/
4. Complete the initUI() method with your codes to show that when we click on a button with label “Quit”,
the application terminates (this is not a complete program and that’s fine).
public QuitButtonEx() {
initUI();
createLayout(quitButton);
setTitle("Quit button");
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
This study source was downloaded by 100000853042928 from CourseHero.com on 03-12-2023 10:20:04 GMT -05:00
https://www.coursehero.com/file/74463433/midtermSpring2020docx/
What is the output of the following programs (5 points each):
1. This is
a two part question. First explain what the following program is intended to do? Then write what will be
the output of this program?
Note that the code is incomplete and you don’t have to correct it or find errors.
Note that you do not have to complete the code or find any error in it.
//constructor
This study source was downloaded by 100000853042928 from CourseHero.com on 03-12-2023 10:20:04 GMT -05:00
https://www.coursehero.com/file/74463433/midtermSpring2020docx/
public final void initUI() {
panel.setLayout(null);
panel.setToolTipText("A Panel container");
panel.add(button);
setTitle("Tooltip");
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
Answer: The code creates a JPanel containing a button named “Button”. When we move
the mouse pointer to the button the tool tip pops up a message as “A button
component” and when we move the mouse pointer to the panel container the tool
tip pops up a message as “A Panel Container”.
Note that this is a partial program and you do not need to complete it.
//Variables
This study source was downloaded by 100000853042928 from CourseHero.com on 03-12-2023 10:20:04 GMT -05:00
https://www.coursehero.com/file/74463433/midtermSpring2020docx/
Answer: This program creates a JFrame named as “Left Right”. We exit the frame when we click on the
close button as the setDefaultCloseOperation is set as EXIT_ON_CLOSE.
Note that it’s an incomplete program and you don’t need to correct it.
}
public static void main(String args[])
{
new CheckBoxExample();
}
}
Answer: This program creates a JFrame named CheckBoxExample. It has two checkboxes named “C++”
and “Java”. The checkbox named java is set as checked as its value is true.
This study source was downloaded by 100000853042928 from CourseHero.com on 03-12-2023 10:20:04 GMT -05:00
https://www.coursehero.com/file/74463433/midtermSpring2020docx/
Powered by TCPDF (www.tcpdf.org)