title: Border and Flow Layouts
body: <p>Okay, so I'm having some trouble with my Programming Exercise today.</p>
  
  <p>The Exercise text goes like this:</p>
  
  <p>(Use the <strong>FlowLayout</strong> manager) Write a program that meets the following requirements:</p>
  
  <ul>
  <li>Create a frame and set its layout to <strong>FlowLayout</strong></li>
  <li>Create two panels and add them to the frame</li>
  <li>Each panel contains three buttons. The panel uses <strong>FlowLayout</strong></li>
  </ul>
  
  <p>The buttons should be named "Button 1", "Button 2" and so on. (i completed the original code)</p>
  
  <p>Now i needed to change my code into <strong>BorderLayout</strong> while moving 1 panel to south, and the other to the center, i tried but it doesn't seem to come out correctly. The buttons are just on the top and bottom.</p>
  
  <p>Original Code (<strong>FlowLayout</strong>):</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class lab5_1 extends JFrame {
  
      public lab5_1() {
          setLayout(new FlowLayout());
  
          // Create two panels
          JPanel panel1 = new JPanel();
          JPanel panel2 = new JPanel();
  
  
          // Add three buttons to each panel
          panel1.add(new JButton(" Button 1 "));
          panel1.add(new JButton(" Button 2 "));
          panel1.add(new JButton(" Button 3 "));
          panel2.add(new JButton(" Button 4 "));
          panel2.add(new JButton(" Button 5 "));
          panel2.add(new JButton(" Button 6 "));
  
  
          // Add panels to frame
          add(panel1);
          add(panel2);
  
      }
  
      public static void main(String[] args) {
          lab5_1 frame = new lab5_1();
          frame.setTitle(" Exercise 12_1 ");
          frame.setSize(600,75);
          frame.setLocationRelativeTo(null); // center frame
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>My attempt at the <strong>BorderLayout</strong>:</p>
  
  <pre><code>public class lab5_2 extends JFrame {
  
      public lab5_2() {
      setLayout(new BorderLayout());
  
       // Create two panels
          JPanel panel1 = new JPanel();
          JPanel panel2 = new JPanel();
  
  
          // Add three buttons to each panel
          panel1.add(new JButton(" Button 1 "));
          panel1.add(new JButton(" Button 2 "));
          panel1.add(new JButton(" Button 3 "));
          panel2.add(new JButton(" Button 4 "));
          panel2.add(new JButton(" Button 5 "));
          panel2.add(new JButton(" Button 6 "));
  
          //Add Panel to frame
          add(panel1, BorderLayout.CENTER);
          add(panel2, BorderLayout.SOUTH);
      }
  
  
      public static void main(String[] args) {
          lab5_2 frame = new lab5_2();
          frame.setTitle(" Exercise 12_2 ");
          frame.setSize(200, 200);
          frame.setLocationRelativeTo(null); // center frame
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
      }
  }
  </code></pre>