Swing into oblivion
I have 2 threads (i think) on Swing, so i thought i might as well put all my Swings questions into 1 thread.. (sorry moderators for the extra threads)
I have read Absolute Java by Walter Savitch, but his chapters on Swing and GUI are very basic and the googling my queries did not help, so heres the situation...
I have created an application to solve the travelling salesman problem using breadth first search. Now i want to create a GUI for it..i understand how to create a basic GUI, with buttons panels frames etc...but there is still more i need to know...
How do i transfer all the outputs that was previously sent to dos prompt into my GUI?
Since you already know how to create the GUI stuff you can add a panel and a text area component to it and simple replace all of your System.out.println(stuff_to_print) with for example:
JTextArea txt = new JTextArea(); //using swing
But the thing is, my TextArea would b in my GUI class..and my System.out.printlns are scattered across other classes...
I have tried the same way using label. I set the labelin my GUI class as static
so that other classes can access it through...
public static JLabel displayPanel=new JLabel ();
and i tried changing all my System.outs into the code above...
But it doesn't work...the display label does not change....
You could try making a GuiInterface class for example, where it would handle all of the printing, so you could replace your System.out.println() with GuiInterface.printMessage(String messageToPrint), and make this method be the one in charge of appending it to the textarea. This way, you wouldn't have to modify all of your original classes if you choose to go back to printing into the terminal, since all you would have to do would be rewrite you GuiInterface class.
Originally Posted by Ant_Magma
By Darren Bell in forum Talk to the Editors
Last Post: 09-20-2002, 11:32 AM
By JB in forum Talk to the Editors
Last Post: 09-16-2002, 09:15 PM
By Valarmathy in forum Java
Last Post: 01-19-2002, 06:35 AM
By Shaun Botha in forum Java
Last Post: 06-25-2001, 10:19 PM
By Fabio Luis De Paoli in forum Java
Last Post: 08-17-2000, 02:06 PM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL