Question
Create a NetBeans project for this activity. The project name should be as follows: Project Name: Lab011_ Example: Lab011_Blanco_Maria Compress the NetBeans project into .rar
- Create a NetBeans project for this activity. The project name should be as follows:
Project Name: Lab011_
Example: Lab011_Blanco_Maria
- Compress the NetBeans project into .rar or .zip format and then upload to the link provided in the LMS.
- Only NetBeans project compressed in .rar or .zip format will be accepted.
Consider the following class:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
public class SwingExample {
public static void main(String args[]) {
JFrame frame = new JFrame();
Container pane = frame.getContentPane();
JButton button = new JButton("Button 3");
pane.add(button, BorderLayout.PAGE_START);
button = new JButton("Button 2");
button.setPreferredSize(new Dimension(200, 100));
pane.add(button, BorderLayout.CENTER);
button = new JButton("Button 3");
pane.add(button, BorderLayout.LINE_START);
button = new JButton("Button 4");
pane.add(button, BorderLayout.PAGE_END);
button = new JButton("Button 5");
pane.add(button, BorderLayout.LINE_END);
}
}
Test Stem / Question | Choices |
1: What happens when you compile? | A: Build was successful but did not create a window. |
B: Compiler error | |
C: Exception is thrown | |
D: Run perfectly and a window is created | |
2: Try to fix the error. What should you do? | A: use .pack() method. |
B: Surround it with try catch | |
C: And throws declaration for Swing | |
D: Nothing, application run perfectly | |
3: Now try to run the application again, what was the result? | A: Build was successful, created a window but the elements are not shown |
B: Build was successful but did not create a window | |
C: Exception is thrown | |
D: Nothing. | |
4: What method should you call to show the elements? | A: setVisible(true) |
B: show() | |
C: setVisibility(SWT.VISIBLE) | |
D: showElements() | |
5: What method should you use for that if you want to arrange the column of the buttons that we created? | A: setLayout() |
B: setLayoutManager() | |
C: addLayout() | |
D: addLayoutManager() | |
6: What parameter type is accepted by the method for adding layout in the container or pane? | A: LayoutManager |
B: Layout | |
C: Frame | |
D: Container | |
7: Say that we would like to arrange the elements of our windows in a single column, how would you write the code? | A:pane.setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS)); |
B: pane.addLayoutManager(new BoxLayout(pane, BoxLayout.PAGE_AXIS)); | |
C:pane.setLayoutManager(new BoxLayout(pane, BoxLayout.LINE_AXIS)); | |
D: pane.addLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS)); | |
8: How about arranging the buttons in a single row? | A:pane.setLayout(new BoxLayout(pane, BoxLayout.LINE_AXIS)); |
B: pane.addLayoutManager(new BoxLayout(pane, BoxLayout.LINE_AXIS)); | |
C:pane.setLayoutManager(new BoxLayout(pane, BoxLayout.PAGE_AXIS)); | |
D: pane.addLayout(new BoxLayout(pane, BoxLayout.LINE_AXIS)); | |
9: If we would like to add an mouseactionto the button, we should add a listener to the element. Choose the correct way on adding a action listener. A. button.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e){ // insert code here } }); B.button.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // insert code here } @Override public void mouseReleased(MouseEvent e) { // insert code here } @Override public void mouseEntered(MouseEvent e) { // insert code here } @Override public void mouseExited(MouseEvent e) { // insert code here } @Override public void mousePressed(MouseEvent e) { // insert code here } }); C.button.addMouseAdapter(new MouseAdapter() { @Override public void mousePressed(MouseEvent e){ // insert code here } }); | A: A & B |
B: B Only | |
C: A only | |
D: All are correct | |
10: Say that you would like to add a multi line area that could display a text. How will you instantiate it?
| A: A, B & C |
B: A only | |
C: B only | |
D: A & B only |
Step by Step Solution
3.27 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
Solution Try to compile the code What is wrong with it A There is compile error because of an unreported exception ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started