If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I have already finished coding the application. Now i want to create a GUI for it. Currently everything is displayed in dos. How do i convert all the System.out.println messages to my GUI without totally messing up the rest of the code?

OK, firstly repaint() and validate() might not be necessary in what I posted above - you could try commenting out those lines and see if it still works. Basically it repaints the contentPane (or whatever panel you tell it to repaint). I'm still learning swing, but I find it helps sometimes - and certainly never seems to hurt.

So to move your System.out messages into the GUI, you have a couple of options. I'm not too sure what you're aiming to achieve, but some or all of the below might help:

You need a component to display the text - this could be label, TextField, TextArea or lots of things. Assuming your output is all text, you could look at the following:

aJLabel.setText("Something has happened");
aJTextField.setText("Something else has happened");
aJTextArea.setText("And now something else which is so big I'm going to need a huge area to fit all the information into");

Obviously you need to declare these components before you use them, and add them to your panel(s) before adding the panel(s) to the contentPane, but all you are really doing is setting the text in a component rather than using System.out.

It sounds as though you have the rest of it running, so I'm guessing your output messages are related to events? If that's the case, wherever you have a System.out, just comment out that line and add one of the above.

If you want to display other data types than Strings, you'll need to cast the data type to a String before you can add it as a String to the component.

Obviously you need to declare these components before you use them, and add them to your panel(s) before adding the panel(s) to the contentPane, but all you are really doing is setting the text in a component rather than using System.out.

So does it mean that after the panel has already been added to the frame i can't edit the panel with setText() etc? meaning the code frame.add(something) has to be at the end of the code?

It sounds as though you have the rest of it running, so I'm guessing your output messages are related to events? If that's the case, wherever you have a System.out, just comment out that line and add one of the above.

However, all my System.outs are spread across a few classes. They are not centralized in 1 class.

Does that mean that for my GUI class, i should set the displaying label, textarea or watever as static, so that the System.outs from those classes can access using

One thing at the time...

Obviously you need to (...) add them to your panel(s) before adding the panel(s) to the contentPane....

Wrong, you can add a container into another container, and so forth, and
then add components/containers into these again, in any order you choose,
but the layoutmanagers have to be set for a container prior to adding
any components/containers into it.

The setText method can be invoked every time you want to set/change some
text in a text component. A panel is not a text component, it is a container,
like a frame, scrollpane, tabbedpane etc. The method has no relevance for
the GUI setup. The method is there for using the GUI.

Does that mean that for my GUI class, i should set the displaying label, textarea or watever as static

Two ways to do this (at least).

1: supply the other classes with constructors or setter methods for handing
over the pointer (variable name) of the GUI class, and declaring the report method in the code I posted as public. E.g. if you in the
main method do this:

2. You could declare outTA and the report method as static and use the
GUI report method anywhere in the application like GUI.report("blabla");

printStackTrace is a public method that applies to all exceptions, it
prints out the calling stack right down to the statement where the exception
occurred.

trim() is a String method, it removes all leading and trailing blanks. It
is especially important when converting numeric strings to numbers, - the
static parse<type> methods of Integer, Float and Double throws
NumberFormatException when they encounter these blanks in the number
string.

JOptionPane.showMessage(...)
param1: the "parent" component (null if there is none),
param2: the message
param3: the dialog titlebar text (you missed that one..., check again )
param4: the message type

PS: again I advise you to study the free and excellent javadoc from Sun, and
how to use it.