|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi, i am having issues with a project i am doing currently. I am converting a command line system into a GUI based one and need to redirect all my System.out.println calls to a JTextArea. (very simple conversion currently) I have numerous classes currently all making println calls so without making my JTextArea global i'm not quite sure how to fix this in a clean (and preferably object oriented) way.
Any help would be very much appreciated. Thanks. |
|
#2
|
|||
|
|||
|
I guess what you are really looking for is the setText() method.
First, for whatever object you want to return, create a function, let's use a String as an example: Code:
class A{
String name;
public A(UserInput){// constructor
name = UserInput;
}
public String Hello(){
return "Hello " + name + "!";
}
}
Then on the other classes, you can get the value of str by creating a new instance of class A: Code:
class GUI{
public void toTextArea{
A newInstance1;
newInstance1 = new A("Redberry");// sets value of contructor
// now we are ready to send stuff to the textfield:
YourTextfield.setText(newInstance1.Hello());// gets the return value of the function Hello()
}
}
And on the texfield you should see Code:
Hello Redberry! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > System.out.println conversion |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|