title: How to connect Java classes to GUI?
body: <p>I'm designing a database that can be accessed through a GUI, I have three classes Main, Database and GUI, When I run the main I get an error and the GUI closes followed by a brief error message which I cannot read, not sure where this is going wrong as i believe it can be a number of issues. Thanks for all your help :)</p>
  
  <p>Here is my main class</p>
  
  <pre><code>public class MainApplication {
  
  @SuppressWarnings("unused")
  public static void main(String[] args) {
  
      VideoStoreGUI window = new VideoStoreGUI();
  } 
  </code></pre>
  
  <p>}</p>
  
  <p>My Database Class:</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.util.Scanner;
  
  import javax.swing.JOptionPane;
  @SuppressWarnings("unused")
  public class DataBase {
  
  static Connection con = null;
  static Statement stmt = null;
  static ResultSet rs = null;
  static Scanner in = new Scanner(System.in);
  
  
  
  public void close_connection() {
      try
      {
          con.close();
          System.out.println("Database Connections Succesully Closed.");
      } 
      catch (SQLException sqle)
      {
          System.out.println("Error: failed to close the database");
      }
  }
  
  public static void addMember(int member_id, String name, String address) // Adding a Member to the Database.
  {
      try {
          String str = "INSERT INTO members (member_id, name, address) values(" + member_id + ", '" + name + "', '"
                  + address + "');";
          int rows = stmt.executeUpdate(str);
  
          System.out.println("Success in adding member");
  
      } catch (SQLException sqle) {
          JOptionPane.showMessageDialog(null, "Error: Could not add member");
      }
  }
  
  
  public static void initialize_database() {
      try {
          Class.forName("com.mysql.jdbc.Driver");
          String url = "jdbc:mysql://localhost:3306/videostore";
          con = DriverManager.getConnection(url, "root", "admin");
          stmt = con.createStatement();
      } catch (Exception e) {
          System.out.println("Error: Failed to connect to database\n" + e.getMessage());
      }
  }
  
  public DataBase()
  {
      initialize_database();      
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and my GUI class: </p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.EventQueue;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.border.EmptyBorder;
  
  import javax.swing.JTabbedPane;
  import javax.swing.JLabel;
  import javax.swing.JTextField;
  import javax.swing.JButton;
  import javax.swing.JMenuBar;
  
  public class VideoStoreGUI extends JFrame {
  private JFrame frame;
  
  DataBase my_database;
  private JPanel contentPane;
  private JTextField textMemberID;
  private JTextField textMemberName;
  private JTextField textMemberAddress;
  
  /**
   * Create the frame.
   */
  public VideoStoreGUI() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(100, 100, 450, 400);
  
      JMenuBar menuBar = new JMenuBar();
      setJMenuBar(menuBar);
      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);
  
      JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
      tabbedPane.setBounds(10, 31, 232, 240);
      contentPane.add(tabbedPane);
  
      JPanel panel = new JPanel();
      tabbedPane.addTab("Members", null, panel, null);
      panel.setLayout(null);
  
      JLabel labelMemberID = new JLabel("Members ID");
      labelMemberID.setBounds(10, 11, 85, 14);
      panel.add(labelMemberID);
  
      JLabel labelMemberName = new JLabel("Members Name");
      labelMemberName.setBounds(10, 36, 85, 14);
      panel.add(labelMemberName);
  
      JLabel labelMemberAddress = new JLabel("Members Address");
      labelMemberAddress.setBounds(10, 61, 85, 14);
      panel.add(labelMemberAddress);
  
      textMemberID = new JTextField();
      textMemberID.setBounds(131, 8, 86, 20);
      panel.add(textMemberID);
      textMemberID.setColumns(10);
  
      textMemberName = new JTextField();
      textMemberName.setColumns(10);
      textMemberName.setBounds(131, 33, 86, 20);
      panel.add(textMemberName);
  
      textMemberAddress = new JTextField();
      textMemberAddress.setColumns(10);
      textMemberAddress.setBounds(131, 58, 86, 20);
      panel.add(textMemberAddress);
  
      JButton buttonAddMember = new JButton("Add Member");
      buttonAddMember.setBounds(10, 86, 102, 23);
      panel.add(buttonAddMember);
  
      JButton buttonRemoveMember = new JButton("Add Member");
      buttonRemoveMember.setBounds(115, 86, 102, 23);
      panel.add(buttonRemoveMember);
  
      JButton buttonSearchMember = new JButton("Add Member");
      buttonSearchMember.setBounds(66, 120, 102, 23);
      panel.add(buttonSearchMember);
  
      JPanel panel_1 = new JPanel();
      tabbedPane.addTab("Products", null, panel_1, null);
  }
  </code></pre>
  
  <p>}</p>