Results 1 to 3 of 3
  1. #1
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

    Exclamation \n not working in GUI (working code, but \n isn't working)

    here is the code:
    Java Code:
    import javax.swing.*;
    public class Creepster extends JFrame{
        private String s;
        private JLabel label;
    
        public Creepster() {
        s = "Hello Mr. Creepster\nThis is my first Java program.\n";
        s += "I wanted to show you that I am learning Java and to thank you for teaching me.";
        label = new JLabel(s);
        add(label);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
        setVisible(true);
        }
        public static void main(String args[]) {
            new Creepster();
        }
    }
    If you compile and run this, it works. The one thing that isn't working is the \n. If you could fix this problem I would be grateful.
    Thanks,
    cc11rocks

  2. #2
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Java Code:
        s = "<html>Hello Mr. Creepster<br>This is my first Java program.<br>";
        s += "I wanted to show you that I am learning Java and to thank you for teaching me.</html>";

  3. #3
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

    Default You rock

    Thank you so much man. This helps me a ton. I didn't know you could use HTML tags in java code. Sweet.
    With lots of [programmer] love,
    cc11rocks

Similar Threads

  1. Been working on a code for days
    By Link01 in forum Java Applets
    Replies: 5
    Last Post: 05-19-2010, 04:55 PM
  2. Why is the code not working
    By sanox in forum New To Java
    Replies: 12
    Last Post: 09-08-2009, 12:28 PM
  3. Next Page Code is not working
    By Java.child in forum AWT / Swing
    Replies: 2
    Last Post: 02-18-2009, 06:26 PM
  4. JNI: Why this code not working?
    By playwin2 in forum Advanced Java
    Replies: 5
    Last Post: 11-25-2008, 02:12 PM
  5. Replies: 8
    Last Post: 05-28-2008, 08:00 AM

Tags for this Thread

Posting Permissions

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