Click here to Skip to main content
15,888,263 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone, i was wondering how can i resovle my following issue:
i have a GUI JFrame named My_Frame, and it contains a jTextArea.
I have another Class named DBConnect witch has a method that prints stuff out of my Database.That method is called getData().
So, i want the output of getData() method to be the text of my TextArea.


jTextArea1.setText(db.getData()); Won't work!

Thanks for your time!


My code for the class : My_Frame

Java
public void jtextArea1(String text) {
    System.out.print(text);
        jTextArea1.append(text);     
    }
    
    public static void main(String args[]) {
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new My_Frame().setVisible(true);
                DBConnect db=new DBConnect();
                jTextArea1.setText(db.getData());
               
            }
        });
Posted
Comments
PIEBALDconsult 29-Dec-15 17:48pm    
Change the result type maybe?
Deathmitsos 29-Dec-15 18:00pm    
I managed to change the type to String, now i get the error: non-static variable jTextArea1 cannot be referenced from a static context.
Sergey Alexandrovich Kryukov 29-Dec-15 18:17pm    
And what is that "static"? is it "main"? Then provide an instance...
—SA
Sergey Alexandrovich Kryukov 29-Dec-15 18:16pm    
The "result of void method" is absurd. If you need "result", why using "void"?
—SA
Deathmitsos 29-Dec-15 18:21pm    
I tried to remove static and convert getData(); method to String but still it couldn't work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900