0

I'm trying to display the console output in a text area. I have a (view) bottom that creates object from class Functional. Inside this class there is method that view all the context of table in table in data base and return the result of the query and printed it into the console window. So I need to display this output from the console window to a text area in the GUI class .

This is the GUI class:

public class MainGUI extends javax.swing.JFrame {
    private void SearchButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
        Functional search = new Functional();
        search.search(SearchTextField.getText(), ItemsComboBox.getSelectedItem().toString());

    }               
}

This is the Functional class:

public class Functional {

    public void viewDtailes(String item) {

        try (Connection con = DriverManager.getConnection("jdbc:odbc:Library_DNS"); 
             Statement stmt = con.createStatement()) {
            if(item.equals("magazins")){
                String sql = "SELECT * FROM " + item;
                ResultSet rs = stmt.executeQuery(sql);
                while(rs.next()){
                    System.out.println(" callNo : " + rs.getString("callno") + " title: " + rs.getString("title")+" Vnom :" + rs.getString("Vnom") + " status: " + rs.getBoolean("status"));
                }
            } else {
                String sql = "SELECT * FROM "+ item;
                ResultSet rs = stmt.executeQuery(sql);
                while(rs.next()){
                    System.out.println("callNo : " + rs.getString("callno")+ " title: " + rs.getString("title")+ " author :" + rs.getString("author") + " status: " + rs.getBoolean("status"));
                }
            }
        } catch (SQLException sqle) {
            System.out.println("Sql Exception :" +sqle.getMessage());
        }
    }
}

The output from console:

output from console

I need to display the console output in this text area GUI:

Display output from GUI

dic19
  • 17,821
  • 6
  • 40
  • 69
Fadi
  • 2,320
  • 8
  • 38
  • 77
  • OK. What stops you? Do you know how to set the content of `JTextArea` component? – PM 77-1 Jan 04 '14 at 23:16
  • yes by using this ViewTextArea.append(" "); but how can i get the output of System.out.println(" ") in the method viewDtailes() in calss Functional and display it in the teat area in class GUI – Fadi Jan 04 '14 at 23:18
  • So? Why not use it in place of `println()`? – PM 77-1 Jan 04 '14 at 23:19

0 Answers0