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

    Default First Java Program-Has Errors-simple GUI

    Hello everyone! I'm glad to be doing some "real" programming (or at least using a "mainstream" programming language). Here is my first Java program. It has some errors. If you could point out how to fix these, that would be great. I learned Java from the book "Java for Dummies", of which I have a copy sitting next to me. I have limited experience with programming including HTML, Autohotkey, and bits and pieces with other languages. I have taken a 2 semester's of computer classes.
    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
    Last edited by cc11rocks; 01-04-2011 at 12:04 AM. Reason: To show incurred errors

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

    Default

    Someone figured this out for me. Just one more error:
    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();
        }
    }
    The error is:
    Java Code:
    Exception in thread "main" java.lang.NoSuchMethodError: main
    If someone could figure this out that would be excellent.
    Thanks,
    cc11rocks

Similar Threads

  1. Simple java program, need help
    By cliffh in forum New To Java
    Replies: 1
    Last Post: 10-21-2010, 04:32 AM
  2. Airline.java program ... getting errors, etc
    By billboardfamily in forum New To Java
    Replies: 17
    Last Post: 07-31-2010, 04:14 AM
  3. Errors with simple program... PLEASE HELP ME!!!
    By maxpower1000sa in forum New To Java
    Replies: 6
    Last Post: 05-04-2009, 12:55 AM
  4. [SOLVED] hello, java program with 2 errors, help
    By einstein1234 in forum New To Java
    Replies: 24
    Last Post: 04-10-2009, 09:50 AM
  5. Replies: 5
    Last Post: 02-04-2009, 02:20 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
  •