Results 1 to 2 of 2
- 01-03-2011, 09:53 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
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.
when I try to compile this (using the command line in Windows through javac filename.java), I get these errors: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(); } }
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 errorsLast edited by cc11rocks; 01-03-2011 at 11:04 PM. Reason: To show incurred errors
- 01-04-2011, 12:15 AM #2
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
Someone figured this out for me. Just one more error:
The error is: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(); } }
If someone could figure this out that would be excellent.Java Code:Exception in thread "main" java.lang.NoSuchMethodError: main
Thanks,
cc11rocks
Similar Threads
-
Simple java program, need help
By cliffh in forum New To JavaReplies: 1Last Post: 10-21-2010, 03:32 AM -
Airline.java program ... getting errors, etc
By billboardfamily in forum New To JavaReplies: 17Last Post: 07-31-2010, 03:14 AM -
Errors with simple program... PLEASE HELP ME!!!
By maxpower1000sa in forum New To JavaReplies: 6Last Post: 05-03-2009, 11:55 PM -
[SOLVED] hello, java program with 2 errors, help
By einstein1234 in forum New To JavaReplies: 24Last Post: 04-10-2009, 08:50 AM -
Debuggin help - simple program non-static method errors
By RR_QQ in forum New To JavaReplies: 5Last Post: 02-04-2009, 01:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks