title: How do I add a class in to a JPanel?
body: <p>This is the JPanel</p>
  
  <pre><code>public class DisplayBoard {
  
    public static void main (String[] args) {
  
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      //The main panel
      JPanel main = new JPanel();
      main.setPreferredSize(new Dimension(600,800) );
      main.setLayout(new BorderLayout());
  
      //The title panel
      JPanel title = new JPanel();
      title.setPreferredSize(new Dimension(400, 120));
      title.setBackground(Color.YELLOW);
      JLabel test1 = new JLabel("Title goes here");
      title.add(test1);
  
      //The side bar panel
      JPanel sidebar = new JPanel();
      sidebar.setPreferredSize(new Dimension(200, 800));
      sidebar.add(AddSubtract);
      sidebar.setBackground(Color.GREEN);
      JLabel test2 = new JLabel("Sidebar goes here");
      sidebar.add(test2);
  
      //The panel that displays all the cards
      JPanel cardBoard = new JPanel();
      cardBoard.setPreferredSize(new Dimension(400,640) );
  
      //adding panels to the main panel
      main.add(cardBoard, BorderLayout.CENTER);
      main.add(title, BorderLayout.NORTH);
      main.add(sidebar, BorderLayout.WEST);
  
      frame.setContentPane(main);
      frame.pack();
      frame.setVisible(true);
  
    }
  }
  </code></pre>
  
  <p>and I want to add this class into the sidebar panel</p>
  
  <pre><code>public class AddSubtract {
  
  int Number = 0;
  private JFrame Frame = new JFrame("Math");
  private JPanel ContentPane = new JPanel();
  private JButton Button1 = new JButton("Add");
  private JButton Button2 = new JButton("Subtract");
  private JLabel Num = new JLabel ("Number: " + Integer.toString (Number));
  
  public AddSubtract() {
  
      Frame.setContentPane(ContentPane);
      ContentPane.add(Button1);
      ContentPane.add(Button2);
      ContentPane.add(Num);
      Button1.addActionListener(new Adding());
      Button2.addActionListener(new Subtracting());
  }
  
  public class Adding implements ActionListener {
      public void actionPerformed(ActionEvent e) {
          Number++;
          Num.setText ("Number: " + Integer.toString (Number));
      }
  }
  
  public class Subtracting implements ActionListener {
      public void actionPerformed(ActionEvent e) {
          Number--;
          Num.setText ("Number: " + Integer.toString (Number));
      }
  }
  
  public void launchFrame(){
      Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Frame.pack();
      Frame.setVisible(true);
  }
  
  public static void main(String args[]){
      AddSubtract Test = new AddSubtract();
      Test.launchFrame();
      }
  }
  </code></pre>
  
  <p>Can someone explain to me how I can do this ?
  I have a feeling that this is not going to work, but I really want to learn the way to do it.</p>