CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Location
    Athens
    Posts
    2

    Talking 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

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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");)
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Aug 2012
    Location
    Athens
    Posts
    2

    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?

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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 code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured