-
August 21st, 2012, 09:42 AM
#1
How can i return my results through a jLabel instead of "System.out.print"?
Hi there!
I have created a project which implements a game played at the terminal. The player explores various rooms( they are described to him on the terminal) and can use some commands (by writing them at the terminal) with which he can go to other rooms,pick up items and do other stuff like that (for those of you who know it,it's called world of zuul).
This project works perfectly! However, I want to go a step forward and create a GUI for the game!In the GUI that i am trying to create, I have used a JMenuBar with the command as JMenu(s).So far so good.The problem is that i am trying to return the results of each command through a jLabel. Thus, i have given an ActionListener at each command which calls the corresponding method from the game and i want the results that are shown with the
"System.out.print" , to be shown at the jLabel...how can i do that?Is it even possible?
I am not entirely sure one can understand exactly what i am trying to do, so if you want any further explanations, please don't hesitate to ask :D
-
August 22nd, 2012, 07:41 AM
#2
Re: How can i return my results through a jLabel instead of "System.out.print"?
Yes it is possible. There are a few ways of doing it but the easiest is to have an instance variable (eg private JLabel myLabel;) that references the JLabel and in the action listeners use the reference to set the text value to display (eg myLabel.setText("Some Text");)
-
August 22nd, 2012, 08:28 AM
#3
Re: How can i return my results through a jLabel instead of "System.out.print"?
yes,i have thought of that,but i don't want to return "some text"..i want to return the text that is displayed at the System.out window..can i turn that into a string?How?
-
August 22nd, 2012, 12:03 PM
#4
Re: How can i return my results through a jLabel instead of "System.out.print"?
Replace "Some Text" with the text you are passing to System.out.println(..).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|