title: Append jtextarea from another class
body: <p>I am making a java application which uses a total of 4 classes, <code>Main</code>, <code>Form1</code>, <code>Form2</code> and <code>ZBC</code>. I am trying to append the <code>JTextArea</code> that is on <code>Form2</code> through some code in the <code>ZBC</code> class. </p>
  
  <p>The first problem is when trying to append the <code>JTextArea</code> I get an error because the <code>JTextarea</code> is not <code>static</code> - I also get an error if I change the <code>JTextArea</code> to <code>static</code>.</p>
  
  <p>I am trying to append the textbox using <code>Form2.jtaConsole.append("TEST");</code> as this is how i've done it previously.</p>
  
  <p>is there any way I can append this text area from another class?</p>
  
  <p>I will post the code from each class below; </p>
  
  <p>Any help appriciaed! </p>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>package com.company;
  public class Main
  {
      public static void main(String[] args)
      {
          Form1 f1 = new Form1();
          f1.open();
      }
  }
  </code></pre>
  
  <p><strong>Form1.java</strong></p>
  
  <pre><code>package com.company;
  import javax.swing.*;
  public class Form1
  {
      //Declare GUI items
      private JComboBox comboBox1;
      private JButton goButton;
      private JPanel jp_one;
  
      public Form1()
      {
          comboBox1.addActionListener(e -&gt;
          {
              Object selected **= comboBox1.getSelectedItem().toString();
          });
  
          goButton.addActionListener(e -&gt;
          {
              Form2 f2 = new Form2(comboBox1.getSelectedItem().toString());
          });
      }
      public static void open()
      {
          JFrame frame = new JFrame("Zebra Print");
          frame.setContentPane(new Form1().jp_one);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);
          frame.setResizable(true);
          frame.pack();
          frame.setLocationRelativeTo(null);
      }
  }
  </code></pre>
  
  <p><strong>Form2.java</strong></p>
  
  <pre><code>package com.company;
  import javax.swing.*;
  
  class Form2
  {
      //Declare GUI items
      public JTextArea jtaConsole;
      public JPanel Jframer;
      public JButton stopButton;
      public JButton startButton;
      String IP1 = "172.20.9.61";
      int PORT1 = 9100;
      ZBC ZBC = new ZBC();
      Thread t1 = new Thread(ZBC);
  
      public Form2(String message)
      {
          JFrame frame = new JFrame("Zebra Print");
          frame.setContentPane(this.Jframer);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setResizable(true);
          frame.setVisible(true);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
  
          jtaConsole.append("//////////// CONSOLE ////////////\n\n");
          jtaConsole.append("- User selected: " + message + "\n");
          jtaConsole.append("- IP: "+IP1+"\n");
          jtaConsole.append("- PORT: "+PORT1+"\n\n");
  
          startButton.addActionListener(e -&gt;
          {
              jtaConsole.append("- Program is now running..\n\n");
              //Starts the ZBC class on a new thread
              t1.start();
          });
  
          stopButton.addActionListener(e -&gt;
                  jtaConsole.append("- Program is now paused..\n\n"));
      }
  }
  </code></pre>
  
  <p><strong>ZBC.java</strong></p>
  
  <pre><code>package com.company;
  import java.io.DataOutputStream;
  import java.io.IOException;
  import java.net.Socket;
  import java.sql.*;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  public class ZBC implements Runnable
  {
  @Override
  public void run()
  {
      while (true)
      {
          // Connect &amp; Select SQL
          String connectionString = "jdbc:sqlserver://:;database=;user=;password=;";
          String SQL = "SELECT [PK_PrintQueueID],[FK_PrinterID],[FK_BarcodeTypeID],[Barcode],[Quantity],[QueueDate],[ProcessedDate] FROM [X].[dbo].[PrintQueue] WHERE ProcessedDate IS NULL";
          Connection connection = null;
          // Time &amp; Date
          DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          Date date = new Date();
          try
          {
              connection = DriverManager.getConnection(connectionString);
              Statement stmt = connection.createStatement();
              Statement stmt2;
              ResultSet rs = stmt.executeQuery(SQL);
              while (rs.next())
              {
                  String FK_BarcodeTypeID = rs.getString("FK_BarcodeTypeID");
                  String barcode = rs.getString("Barcode");
                  String[] parts = barcode.split("-");
                  String part1 = parts[0];
                  String SQL2 = "UPDATE PrintQueue SET ProcessedDate = '" + dateFormat.format(date) + "' WHERE PK_PrintQueueID = '" + rs.getString("PK_PrintQueueID") + "'";
                  stmt2 = connection.createStatement();
                  stmt2.executeUpdate(SQL2);
  
                  if (FK_BarcodeTypeID.equals("1"))
                  {
                      // Type 128 barcode.
                      String zpl = "^XA^BY2,3,140^FT80,200^BCN,Y,N,N^FD&gt;:" + rs.getString("Barcode") + "^FS^FT200,250^A0N,42,40^FH^FD" + part1 + "^FS^XZ";
                      //printlabel(zpl);
                      System.out.println("New serialized barcode added.\nPrinting: " + (rs.getString("Barcode")));
                      System.out.println("Process date: " + dateFormat.format(date) + ".\n");
                      Form2.jtaConsole.append("TEST");
  
                  } else
                  {
                      // Type 39 barcode.
                      String zpl = "CT~~CD,~CC^~CT~ ^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR4,4~SD15^JUS^LRN^CI0^XZ^XA^MMT^PW674^LL0376 ^LS0 ^BY2,3,151^FT84,249^BCN,,Y,N^FD&gt;:" + rs.getString("Barcode") + "^FS ^PQ1,0,1,Y^XZ";
                      //printlabel(zpl);
                      System.out.println("New un-serialized barcode added.\nPrinting: " + (rs.getString("Barcode")));
                      System.out.println("Process date: " + dateFormat.format(date) + ".\n");
                  }
              }
          } catch (SQLException e)
          {
              e.printStackTrace();
          }
          try
          {
              Thread.sleep(3000);
          }
          catch (InterruptedException e)
          {
              e.printStackTrace();
          }
          System.out.println("Checking for new barcode..");
      }
  }
  public void printlabel(String zpl)
  {
      try
      {
          Socket clientSocket;
          clientSocket = new Socket(IP,PORT);
          DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
          outToServer.writeBytes(zpl);
          clientSocket.close();
      }
      catch (IOException e)
      {
          e.printStackTrace();
      }
  }
  }
  </code></pre>