Results 1 to 7 of 7
  1. #1
    jamesyoui is offline Member
    Join Date
    Aug 2013
    Posts
    5
    Rep Power
    0

    Cool How to make something like system.out.println in swing

    I need something for my new program where it can just print text on a page like the console instead of having to change the text of a text box. I have checked almost every website but I cant figure out how to do it

    Basicaly I want to do this in a swing program
    //Prints on the screen
    System.out.println("Welcome");
    try {
    Thread.sleep(2000);
    } catch(InterruptedException e) {
    }
    System.out.println("What is your name?")
    //This pauses the program
    try {
    Thread.sleep(2000);
    } catch(InterruptedException e) {
    }
    System.out.println("Type it below")
    Last edited by jamesyoui; 08-02-2013 at 11:26 AM.

  2. #2
    Liq
    Liq is offline Member
    Join Date
    Jul 2013
    Posts
    10
    Rep Power
    0

    Default Re: How to make something like system.out.println in swing

    Quote Originally Posted by jamesyoui View Post
    I need something for my new program where it can just print text on a page like the console instead of having to change the text of a text box. I have checked almost every website but I cant figure out how to do it
    If what you are looking for is a way to display text on a frame without using a text box just use a label like below.

    Java Code:
    JLabel x = new JLabel("Text goes here");
    Hope it helped!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: How to make something like system.out.println in swing

    jamesyoui, please go through the Forum Rules, particularly the second paragraph. I've closed the other two threads you started for the same question. Any more multiposting and you may be banned for a period.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    jamesyoui is offline Member
    Join Date
    Aug 2013
    Posts
    5
    Rep Power
    0

    Default Re: How to make something like system.out.println in swing

    Sorry that didn't work. I'm using net beans ide and I have got a button to start the program. Its meant to say something like "You wake up" "you look around" "Its very dark". So I need something where I can have an area that when I press the button it displays them in the same place one after each other

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: How to make something like system.out.println in swing

    Which is what will happen with a JLabel.
    "didn't work" is pretty meaningless if you are looking for help.
    You need to show what you have done and also what happens and what should have happened.
    Please do not ask for code as refusal often offends.

  6. #6
    jamesyoui is offline Member
    Join Date
    Aug 2013
    Posts
    5
    Rep Power
    0

    Default Re: How to make something like system.out.println in swing

    This is the code I have
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    JOptionPane.showMessageDialog(null, "This game is in dev");
    JLabel x = new JLabel("Text goes here");
    }
    its ment to display text goes here
    It runs until I click ok on the dialogue
    Then it just crashed this is the error message I get
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
    symbol: class JLabel
    location: class LegendQuest.LegendQuest
    at LegendQuest.LegendQuest.jButton1ActionPerformed(Le gendQuest.java:130)
    at LegendQuest.LegendQuest.access$000(LegendQuest.jav a:12)
    at LegendQuest.LegendQuest$1.actionPerformed(LegendQu est.java:66)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6505)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
    at java.awt.Component.processEvent(Component.java:627 0)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719 )
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:735)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:708)
    at java.awt.EventQueue$4.run(EventQueue.java:706)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 705)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:91)

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: How to make something like system.out.println in swing

    "Uncompilable source code" tends to mean you are trying to run somehting that hasn't actually compiled.
    Ensure your code compiles before you run it.
    In your case the LegendQuest class has a problem that needs resolving.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Replies: 8
    Last Post: 06-21-2011, 02:21 PM
  2. System.out.println
    By JohnDoe in forum New To Java
    Replies: 1
    Last Post: 09-05-2010, 10:14 AM
  3. Println VS system.out.println
    By ccie007 in forum New To Java
    Replies: 2
    Last Post: 05-20-2010, 08:52 AM
  4. difference between system.out.println() & out.println()
    By wickedrahul9 in forum Advanced Java
    Replies: 5
    Last Post: 10-18-2008, 11:06 PM
  5. System.out.println
    By Sniper-X in forum Advanced Java
    Replies: 10
    Last Post: 05-05-2008, 03:41 PM

Posting Permissions

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