title: How to use method from a class to a GUI?
body: <p>My GUIForm gets an error if I use a method from the other class I have. Can u guys also tell me if what I did is right? Some revisions is appreciated. Thank you! Here's my code:</p>
  
  <p><em><strong>Books.java</em></strong></p>
  
  <pre><code>package exer_sec;
  
  public class Books {
  
  private String author;
  private String title;
  private int numOfPages;
  
  private String[] arr_author;
  private String[] arr_title;
  private long[] arr_pages;
  
  public Books(String[] author, String[] title, long[] numOfPages) {
      this.arr_author = author;
      this.arr_title = title;
      this.arr_pages = numOfPages;
  }
  
  public Books() {
      this.author = "JK Rowling";
      this.title = "Harry Potter";
      this.numOfPages = 223;
  }
  
  public String[] getAuthor() {
      return arr_author;
  }
  
  public void setAuthor(String[] author) {
      this.arr_author = author;
  }
  
  public String[] getTitle() {
      return arr_title;
  }
  
  public void setTitle(String[] title) {
      this.arr_title = title;
  }
  
  public long[] getNumOfPages() {
      return arr_pages;
  }
  
  public void setNumOfPages(long[] numOfPages) {
      this.arr_pages = numOfPages;
  }
  
  @Override
  public String toString() {
  return "Author = " + arr_author + "  | Title = " + arr_title + " | Pages = " +    arr_pages;
  }
  
  public void displayAuthors() {
      System.out.print("Authors: ");
  
      if (arr_author.length &gt;= 1) {
          System.out.print(arr_author[0]);
      }
  
      for (int i = 1; i &lt; arr_author.length; i++)
          System.out.print(", " + arr_author[i] );
      System.out.println("");
      /*
      for (int i = 1; i &lt; arr_author.length; i++)
          System.out.println(arr_author[i] );
      */
  }
  
  public void displayTitles() {
      System.out.print("Titles: ");
  
      if (arr_title.length &gt;= 1) {
          System.out.print(arr_title[0]);
      }
  
      for (int i = 1; i &lt; arr_title.length; i++)
          System.out.print(", " + arr_title[i] );
      System.out.println("");
  }
  
  public void displayPages() {
      System.out.print("Pages: ");
  
      if (arr_pages.length &gt;= 1) {
          System.out.print(arr_pages[0]);
      }
  
      for (int i = 1; i &lt; arr_pages.length; i++)
          System.out.print(", " + arr_pages[i] );
      System.out.println("");
  }
  
  public void display1() {
      displayAuthors();
      displayTitles();
      displayPages();
  }
  
  public void display2(Books[] x) {
      for (int i = 0; i &lt; x.length; i++) {
          System.out.println(x[i]);
      }
  }
  
  }
  </code></pre>
  
  <p><em><strong>Main.java</em></strong></p>
  
  <pre><code>package exer_sec;
  
  public class Main {
  
  public static void main(String[] args) {
  
      Books b1 = new Books();
      BubbleSort bub = new BubbleSort();
  
      String[] authors = {"James Dashner", "Veronica Roth", "Joanne Rowling",
                          "Suzanne Collins", "Rick Riordan"};
      String[] titles = {"Maze Runner", "Divergent", "Harry Potter",
                          "Hunger Games", "Percy Jackson"};
      long[] pages = {374, 487, 309, 391, 384};
  
      b1.setAuthor(authors);
      b1.setTitle(titles);
      b1.setNumOfPages(pages);
  
      System.out.print("OUTPUT \n");
      b1.display1();
  
      System.out.print("\nBUBBLE SORT \n");
      bub.sortString(authors);
      bub.sortString(titles);
      bub.sortNum(pages);
      b1.display1();
  
  }
  
  }
  </code></pre>
  
  <p><em><strong>BubbleSort.java</em></strong></p>
  
  <pre><code>package exer_sec;
  
  public class BubbleSort extends Books {
  
  public void sortString(String[] x) {
      int j;
      String temp;
      boolean flag = true;
  
      while (flag) {
  
          flag = false;
  
          for (j = 0; j &lt; x.length - 1; j++) {
              if (x[j].compareTo(x[j + 1]) &gt; 0) {
                  temp = x[j];
                  x[j] = x[j + 1];
                  x[j + 1] = temp;
                  flag = true;
              }
          }
      }
  }
  
  public void sortNum(long[] x) {
      int j;
      int temp;
      boolean flag = true;
  
      while (flag) {
  
          flag = false;
          for (j = 0; j &lt; x.length - 1; j++) {
              if (x[j] &gt; x[j + 1]) {
                  temp = (int) x[j];
                  x[j] = x[j + 1];
                  x[j + 1] = temp;
                  flag = true;
              }
          }
      }
  
  }
  }
  </code></pre>
  
  <p><em><strong>Form.java</em></strong>
  the GUI. this is for the button that would perform the action but it wouldnt work T_T</p>
  
  <pre><code>package exer_sec;
  import java.util.Arrays;
  
  public class Form extends javax.swing.JFrame {
  
  Books b1 = new Books();
  
  public Form() {
      initComponents();
  }
  
  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
  private void initComponents() {
  
      jPanel1 = new javax.swing.JPanel();
      jScrollPane1 = new javax.swing.JScrollPane();
      txtarea_beforesort = new javax.swing.JTextArea();
      jLabel2 = new javax.swing.JLabel();
      jPanel2 = new javax.swing.JPanel();
      jScrollPane2 = new javax.swing.JScrollPane();
      txtarea_aftersort = new javax.swing.JTextArea();
      jLabel3 = new javax.swing.JLabel();
      jButton1 = new javax.swing.JButton();
      jButton2 = new javax.swing.JButton();
      jPanel3 = new javax.swing.JPanel();
      jScrollPane3 = new javax.swing.JScrollPane();
      jTextArea3 = new javax.swing.JTextArea();
      jLabel1 = new javax.swing.JLabel();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
      jPanel1.setBackground(new java.awt.Color(204, 204, 255));
      jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
  
      txtarea_beforesort.setColumns(20);
      txtarea_beforesort.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N
      txtarea_beforesort.setRows(5);
      jScrollPane1.setViewportView(txtarea_beforesort);
  
      jLabel2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
      jLabel2.setText("BEFORE SORTING...");
  
      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(
          jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel1Layout.createSequentialGroup()
              .addContainerGap()
              .addComponent(jScrollPane1)
              .addContainerGap())
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
              .addContainerGap(135, Short.MAX_VALUE)
              .addComponent(jLabel2)
              .addGap(128, 128, 128))
      );
      jPanel1Layout.setVerticalGroup(
          jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel1Layout.createSequentialGroup()
              .addComponent(jLabel2)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
              .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
              .addGap(14, 14, 14))
      );
  
      jPanel2.setBackground(new java.awt.Color(255, 204, 204));
      jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
  
      txtarea_aftersort.setColumns(20);
      txtarea_aftersort.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N
      txtarea_aftersort.setRows(5);
      jScrollPane2.setViewportView(txtarea_aftersort);
  
      jLabel3.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
      jLabel3.setText("AFTER SORTING...");
  
      javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
      jPanel2.setLayout(jPanel2Layout);
      jPanel2Layout.setHorizontalGroup(
          jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel2Layout.createSequentialGroup()
              .addContainerGap()
              .addComponent(jScrollPane2)
              .addContainerGap())
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
              .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(jLabel3)
              .addGap(132, 132, 132))
      );
      jPanel2Layout.setVerticalGroup(
          jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel2Layout.createSequentialGroup()
              .addComponent(jLabel3)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
              .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
              .addContainerGap())
      );
  
      jButton1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
      jButton1.setText("Bubble Sort");
      jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButton1ActionPerformed(evt);
          }
      });
  
      jButton2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
      jButton2.setText("Selection Sort");
  
      jPanel3.setBackground(new java.awt.Color(255, 255, 204));
  
      jTextArea3.setColumns(20);
      jTextArea3.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N
      jTextArea3.setRows(5);
      jScrollPane3.setViewportView(jTextArea3);
  
      javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
      jPanel3.setLayout(jPanel3Layout);
      jPanel3Layout.setHorizontalGroup(
          jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel3Layout.createSequentialGroup()
              .addContainerGap()
              .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
              .addContainerGap())
      );
      jPanel3Layout.setVerticalGroup(
          jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel3Layout.createSequentialGroup()
              .addContainerGap()
              .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
              .addContainerGap())
      );
  
      jLabel1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
      jLabel1.setText("PAGADUAN_exer_02");
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addContainerGap()
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                          .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                          .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                          .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                      .addContainerGap())
                  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                      .addGap(0, 20, Short.MAX_VALUE)
                      .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))))
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addContainerGap()
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                      .addComponent(jButton1)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(jButton2)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGap(18, 18, 18)
                      .addComponent(jLabel1))
                  .addGroup(layout.createSequentialGroup()
                      .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
              .addContainerGap(13, Short.MAX_VALUE))
      );
  
      pack();
  }// &lt;/editor-fold&gt;                        
  
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      // TODO add your handling code here:
      txtarea_beforesort.append(b1.display1());
      //txtarea_beforesort.setText(b1.display1());
  }                                        
  
  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
      /* Set the Nimbus look and feel */
      //&lt;editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "&gt;
      /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
       * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
       */
      try {
          for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
                  javax.swing.UIManager.setLookAndFeel(info.getClassName());
                  break;
              }
          }
      } catch (ClassNotFoundException ex) {
          java.util.logging.Logger.getLogger(Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
          java.util.logging.Logger.getLogger(Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
          java.util.logging.Logger.getLogger(Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (javax.swing.UnsupportedLookAndFeelException ex) {
          java.util.logging.Logger.getLogger(Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      }
      //&lt;/editor-fold&gt;
  
      /* Create and display the form */
      java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
              new Form().setVisible(true);
          }
      });
  }
  // Variables declaration - do not modify                     
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JPanel jPanel3;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JScrollPane jScrollPane2;
  private javax.swing.JScrollPane jScrollPane3;
  private javax.swing.JTextArea jTextArea3;
  private javax.swing.JTextArea txtarea_aftersort;
  private javax.swing.JTextArea txtarea_beforesort;
  // End of variables declaration                   
  }
  </code></pre>