Reputation: 27
I am a Java newbie and recently just finished making a game of Big Two (a card game) that uses that console output to play. However I am now required to make another class that is a GUI which contains a JTextArea and I am supposed to transport basically the whole console output to the JTextArea. I have done a lot of searching on google but most of them seems to be implementing a GUI within the same class. So my question is, how do I transport it?
Upvotes: 0
Views: 101
Reputation: 2784
I hope I got it right - After creating a GUI base, You just create a JTextArea, add it to Your GUI. And when needed, append the output. I'd go something like this
public JTextArea output;
public void initializeOutput() {
output = new JTextArea(5, 20);
JScrollPane scrollPane = new JScrollPane(output);
output.setEditable(false);
//add JTextArea to your GUI.
}
public void addToOutput(String textToAdd) {
output.append("\n" + textToAdd);
}
more info on JTextArea can be found in docs
Upvotes: 0
Reputation: 1699
In my experience, the best method is to use the design pattern Model View Controller.
There, you have 3 components (usually a package each):
The Model is the logic on your program, tha part that "thinks", it doesn't display anything or get touched by the user.
The View is the User Interface, where the user see the output of the program, and where he introduces the input.
The Controller connects both. Imagine it as a class that have two objects: the object view and the object model, and it takes the data from one to another.
You should study it a bit if you have time, but if you don't, the fast way is:
You have to modify your program's methods so it returns values instead of printing them to console. Once you do this, excecute it from the controller class and just put the values on the TextArea using setText().
Upvotes: 1