title: how to align buttons in the middle java
body: <p>I am a beginner in Java, but somehow have a bit of knowledge but still beyond. I wanted to ask , how do align buttons in this main menu I just created. The buttons are somehow aligned horizontally.</p>
  
  <p>This is my code :</p>
  
  <pre><code>import javax.swing.*;
  
  import java.awt.*;
  
  import java.awt.event.*;
  
  
  
  class mainmenu extends JFrame 
  {
  
  
      JButton b1;
      JLabel l1;
      JButton b2;
  
      public mainmenu() {
  
  
          setResizable(false);    
          setLocation(100, 100);
          setSize(500, 500);
          setVisible(true);
  
          setLayout(new BorderLayout());
  
          JLabel background=new JLabel(new ImageIcon("C:\\Users\\Master Boat\\Desktop\\PH\\BG HOROR.png"));
  
          add(background);
  
          background.setLayout(new FlowLayout());
  
          l1=new JLabel("Here is a button");
          b1=new JButton("I am a button");
          b2=new JButton(" EXIT! ");
          b1.addActionListener(new btnFunc());
  
  
          background.add(l1);
          background.add(b1);
          background.add(b2);
      }
  
      public void armaged() {
          add(new gamesamplingbeta());
  
      }
  
      public static void main(String args[]) 
      {
          new mainmenu();
      }
      public class btnFunc implements ActionListener {
  
          public void actionPerformed (ActionEvent e) {
  
  
          }   
  
  
      }
  
      public class btnFunc2 implements ActionListener {
  
          public void actionPerformed2 (ActionEvent e) {
  
              System.exit(1);
          }
      }
  }
  </code></pre>