Question: JAVA ***PLEASE SHOW SOLUTION*** Procedure: Create a NetBeans project for this activity. Consider the following class: import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import javax.swing.JButton; import

JAVA ***PLEASE SHOW SOLUTION*** Procedure: Create a NetBeans project for this activity.

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);

}

}

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 mouse action to 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. JTextArea textArea = new JTextArea("Text", 20, 20); B. JTextArea textArea = new JTextArea(20, 20); C. JTextArea textArea = new JTextArea(Text"); A: A, B & C B: A only C: B only D: A & B only

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!