Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Name a Swing component that can act as a standalone GUI window. What method must

ID: 3818932 • Letter: N

Question

Name a Swing component that can act as a standalone GUI window. What method must be implemented by ActionListeners? Suppose F is a JFrame. Write a code to get the content pane from F and set its layout manager to BorderLayout. Name the 5 positions of a BorderLayout. (T/F) You can write a class that extends JFrame. (T/F) A GUI component can implement multiple interfaces in Java. Write a line of code that will place a button called "myButton" on the NORTH position of a panel called "buttonPanel". In the coordinate system used by Swing, what comer of a component is position (0, 0)? What layout manager can be used to produce a grid of components of the same size?

Explanation / Answer

1. JFrame and JPanel

2. actionPerformed(ActionEvent)

3. JFrame f = new JFrame();

    …..

    container contentPane = f.getContentPane();

    contentPane.setLayout(new FlowLayout());

4. North, South, East, West, Center

5. Yes, the JFrame can be extended, to create a standalone application.

6. Yes

7. private JPanel buttonPanel;

    private JButton myButton

    add(buttonPanel);

    buttonPanel = new JPanel();

     add(buttonPanel, BorderLayout,WEST);

     myButton = new JButton(“Button”);

     myButton.addActionListener(this);

     buttonPanel.add(myButton, BorderLayout.NORTH);

8. Top-left corner

9. GridLayout