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

    Default First Java Program-Compile Errors (errors are posted)-simple GUI

    Here is my first Java program(yes i'm a noob). It has some errors. If you could point out how to fix these, that would be great.
    Thanks,
    cc11rocks
    PS: I'm sending this to my computer teacher in middle school.
    Java Code:
    import javax.swing.*;
    public class Creepster extends JFrame{
    	JLabel label = new JLabel("Hello Mr. Creepster");
    	JLabel label = new JLabel("This is my first Java program.");
    	JLabel label = new JLabel("I wanted to show you that I am learning Java and to thank you for teaching me.");
    		
    }
    public Creepster() {
    add(label);
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    pack();
    setVisible(true);
    }
    class Showcreepster {
    public static void main(String args[]) {
    new Creepster();
    }
    }
    when I try to compile this (using the command line in Windows through javac filename.java), I get these errors:
    Java Code:
    firstappinjava.java:7: class, interface, or enum expected
    public Creepster(){ //the carret thing is pointing to the C in 
     //Creepster
    firstappinjava.java:9: class, interface, or enum expected
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    //the carret thing is pointing to the s in setDefault...
    firstappinjava.java:11: class, interface, or enum expected
    setVisible(true); //carret pointing to the s in setVisible(true);
    firstappinjava.java:12: class, interface, or enum expected 
    } //the carret is pointing to the }
    5 errors

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

    Default

    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.DO_NOTHING_ON_CLOSE);
        pack();
        setVisible(true);
        }
    }
    class Showcreepster {
        public static void main(String args[]) {
            new Creepster();
        }
    }

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

    Default One more error:Exception in thread "main" java.lang.NoSuchMethodError: main

    Quote Originally Posted by JavaHater View Post
    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.DO_NOTHING_ON_CLOSE);
        pack();
        setVisible(true);
        }
    }
    class Showcreepster {
        public static void main(String args[]) {
            new Creepster();
        }
    }
    This almost works. Thanks for this.
    There is one error message now saying:
    Java Code:
    Exception in thread "main" java.lang.NoSuchMethodError: main
    If you could fix this, I would be very much pleased.
    Thank you for your interest and help,
    cc11rocks

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

    Default

    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();
        }
    }

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

    Default

    Quote Originally Posted by JavaHater View Post
    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();
        }
    }
    Thank you very much. It works!
    With Gratitude,
    cc11rocks

Similar Threads

  1. First Java Program-Has Errors-simple GUI
    By cc11rocks in forum New To Java
    Replies: 1
    Last Post: 01-04-2011, 01:15 AM
  2. compile errors (how do I fix)
    By rhythmiccycle in forum New To Java
    Replies: 4
    Last Post: 01-03-2011, 11:33 PM
  3. Replies: 12
    Last Post: 01-18-2010, 12:05 AM
  4. Errors with simple program... PLEASE HELP ME!!!
    By maxpower1000sa in forum New To Java
    Replies: 6
    Last Post: 05-04-2009, 12:55 AM
  5. Replies: 5
    Last Post: 02-04-2009, 02:20 AM

Posting Permissions

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