title: how to show output from console to JTextArea
body: <p>I am beginner in Java Programming. How can i show my output from console to JTextArea. Here my code only show the output console. Anyone could tell or show me how can i do it.Thanks.</p>
  
  <pre><code>import java.sql.*;
  
  public class Route
  {
  
  public void routeList() 
  {
  
      Connection conn = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "YarraTram";
      String driver = "com.mysql.jdbc.Driver";
      String userName = "root"; 
      String password = "abc123";
      try 
      {
          Class.forName(driver).newInstance();
          conn = DriverManager.getConnection(url+dbName,userName,password);
  
          PreparedStatement statement = conn.prepareStatement("Select rid,route from route");
          ResultSet result = statement.executeQuery();
  
          while(result.next())
          {
              System.out.println(result.getString(1)+" "+result.getString(2));
  
          } 
  
          conn.close();
  
      } 
      catch (Exception e) 
      {
          e.printStackTrace();
      }
   }
  } 
  </code></pre>
  
  <p>here is another file</p>
  
  <pre><code> import java.awt.FlowLayout;
   import javax.swing.JFrame;
   import javax.swing.JButton;
   import javax.swing.JTextArea;
  
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
  
  
   public class GUI
   {
      public void createAndShowGUI()
   {
  
      JButton button2 = new JButton("Route");
  
      //create a frame
      JFrame frame = new JFrame("Yarra Tram Route Finder");
  
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      frame.setLayout(new FlowLayout());
  
      frame.add(button2);
  
  button2.addActionListener(new ActionListener() 
      {
  
              public void actionPerformed(ActionEvent e)
              {
  
              //Execute when button is pressed
                      showNewFrame();
                      Route route = new Route();
                      route.routeList();
              }
             public void showNewFrame() 
              {
                  JFrame frame = new JFrame("Yarra Tram Route Finder (Route)" );
                  JTextArea textArea = new JTextArea();
  
                  frame.add(textArea);
                  frame.setSize(500,120);
                  frame.setLocationRelativeTo( null );
                  frame.setVisible( true );
                  textArea.setEditable( false );
  
              }
      });
              frame.pack();
      frame.setSize(350,100);
      frame.setVisible(true); 
     }
  }   
  </code></pre>