Problem

Panels and FramesThe following question was posted on a Java Developer Forum. Be the “expe...

Panels and Frames

The following question was posted on a Java Developer Forum. Be the “expert,” and explain why this user sees only one panel on his/her frame. “Trying to add two JPanels in one JFrame but only ever get one JPanel and it’s always the last. Can someone please explain this to me? Thanks”

    import java.awt.*;    import javax.swing.*;    // Program modifed for anonymity and clarity    // Original posted program was less concise and poorly formatted    public class query    {         public static void main(String[] args)         {              JFrame myFrame = new JFrame("Anonymous");              myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);              myFrame.setSize(800, 300);              JPanel panel_1 = new JPanel(new GridLayout(2, 3, 5, 5));              panel_1.add(new JButton("Main"));              panel_1.add(new JButton("Help"));              panel_1.add(new JButton("Save"));              JPanel panel_2 = new JPanel(new GridLayout(2, 3, 5, 5));              panel_2.add(new JButton("1"));              panel_2.add(new JButton("2"));              panel_2.add(new JButton("3"));              panel_2.add(new JButton("4"));              panel_2.add(new JButton("5"));              panel_2.add(new JButton("6"));              myFrame.add(panel_1);              myFrame.add(panel_2);              myFrame.setVisible(true);         }    }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 18
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT