Question 1

Draw the GUI component that would be produced by the following code. Suppose that the image contained in car.png looks like:

   JPanel buttonPanel = new JPanel();
   buttonPanel.setLayout(
      new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
   buttonPanel.add(new JButton("Button One"));
   buttonPanel.add(new JButton("Button Two"));
   buttonPanel.add(new JButton("Button Three"));

   JPanel keyPanel = new JPanel();
   keyPanel.setLayout(new GridLayout(4,2));
   keyPanel.add(new JButton("A"));
   keyPanel.add(new JButton("B"));
   keyPanel.add(new JButton("C"));
   keyPanel.add(new JButton("D"));
   keyPanel.add(new JButton("E"));
   keyPanel.add(new JButton("F"));
   keyPanel.add(new JButton("G"));
   keyPanel.add(new JButton("H"));

   JLabel carLabel = 
     new JLabel(new ImageIcon("car.png"));

   JLabel label = 
     new JLabel("ARE WE HAVING FUN YET?", 
                SwingConstants.CENTER);

   JList list = 
     new JList(new String[]{"Beans", "Carrots", 
                            "Spinach", "Corn"});

   JFrame frame = new JFrame("Layout Test");
   frame.add(buttonPanel, BorderLayout.NORTH);
   frame.add(keyPanel, BorderLayout.WEST);
   frame.add(label, BorderLayout.SOUTH);
   frame.add(carLabel, BorderLayout.CENTER);
   frame.add(list, BorderLayout.EAST);
        
   frame.pack();
   frame.setVisible(true);
  
Draw the GUI component that would be produced by the following code. Suppose that the image contained in car.png looks like:

   JPanel buttonPanel = new JPanel();
   buttonPanel.setLayout(
      new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
   buttonPanel.add(new JButton("Button One"));
   buttonPanel.add(new JButton("Button Two"));
   buttonPanel.add(new JButton("Button Three"));

   JPanel keyPanel = new JPanel();
   keyPanel.setLayout(new GridLayout(4,2));
   keyPanel.add(new JButton("A"));
   keyPanel.add(new JButton("B"));
   keyPanel.add(new JButton("C"));
   keyPanel.add(new JButton("D"));
   keyPanel.add(new JButton("E"));
   keyPanel.add(new JButton("F"));
   keyPanel.add(new JButton("G"));
   keyPanel.add(new JButton("H"));

   JLabel carLabel = 
     new JLabel(new ImageIcon("car.png"));

   JLabel label = 
     new JLabel("ARE WE HAVING FUN YET?", 
                SwingConstants.CENTER);

   JList list = 
     new JList(new String[]{"Beans", "Carrots", 
                            "Spinach", "Corn"});

   JFrame frame = new JFrame("Layout Test");
   frame.add(buttonPanel, BorderLayout.NORTH);
   frame.add(keyPanel, BorderLayout.WEST);
   frame.add(label, BorderLayout.SOUTH);
   frame.add(carLabel, BorderLayout.CENTER);
   frame.add(list, BorderLayout.EAST);
        
   frame.pack();
   frame.setVisible(true);
  

Q: What design pattern does Swing layout management employ?

Q: What design pattern does Swing layout management employ?

A: The Strategy design pattern.