title: How can I correctly place a JPanel onto a JFrame?
body: <p>I'm currently studying Software Engineering at Uni and I'm struggling to come to terms with how to add a JPanel onto a JFrame properly. My JPanel has a couple of buttons as well as a JLabel which changes by clicking on one of the buttons and using an ActionListener.</p>
  
  <p>I know there are several ways to do it, and here is what I've been trying but I can't for the life of me figure it out!</p>
  
  <p>I know I am doing loads wrong but what is it?</p>
  
  <p>Here is my code:</p>
  
  <p><strong>UIPanelOne:</strong></p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.*;
  import javax.swing.event.*;
  
  
  public class UIPanelOne extends JPanel implements ActionListener {
  
  private JButton yes, no, cancel;
  private JPanel panel;
  private JLabel l1, l2;
  
  UIPanelOne() {
  
      super();
      setVisible(true);
  
      //label dec
      panel = new JPanel();
  
      //buttons
      yes = new JButton("Yes");
      no = new JButton("No");
      cancel = new JButton("Cancel");
  
      //label dec
      l1 = new JLabel("Hello");
  
      //button dec
      panel.setLayout(new BorderLayout());
      panel.add(yes);
      panel.add(no);
      panel.add(cancel);
      panel.add(l1);
  
  }
  
  public void actionPerformed(ActionEvent e) {
  
      if (e.getSource() == yes) {
  
          l1.setText("OK then!");
      }else if (e.getSource() == no){
  
          l1.setText("Goodbye then!");
  
  
      }else if(e.getSource() == cancel){
  
          System.exit(0);
      }
  
  
  }
  
  public JComponent getGUI(){
  
      return panel;
  }
  }
  </code></pre>
  
  <p><strong>UIFrame:</strong></p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  
  public class UIFrame extends JFrame{
  
  
  //constructor
  public UIFrame(){
  
      //layout
      super("Can I help you?");
      setSize(400,600);
      setLayout(new BorderLayout());
      setVisible(true);
      setLocationRelativeTo(null);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      UIPanelOne hello = new UIPanelOne();
  
      getContentPane().add(hello.getGUI());
     }
  }
  </code></pre>
  
  <p><strong>UITest:</strong></p>
  
  <pre><code>public class UITest {
  
  public static void main(String[] args){
  
  UIFrame frame = new UIFrame();
  frame.pack();
  
  }
  
  }
  </code></pre>
  
  <p>I know alot of this is probably wrong and I'm a total amateur but I'm hoping to get better with some help!</p>