Hey there!

I was wondering if someone here could help me out a bit. I'm a beginner in Java and I'm struggling a bit with understanding if it is me who is doing something wrong or if something is just missing from my software to run the thing I'm trying to do.

What I have here is some basic applet from my textbook. What it is supposed to do, is make a small clutter of symbols and write a qoute, but when I try to compile and run it, I get the following errors:

'class' or 'interface' expected
javax.swing.JApplet;
^
'class' or 'interface' expected
java.awt.*;
^
'class' or 'interface' expected
Einstein JApplet
^
3 errors

This is the applet here:

//Einstein.java
//Demonstrates a basic applet. 

javax.swing.JApplet;
java.awt.*;

Einstein JApplet
{
	//Draws some forms and writes a qoute. 
	paint (Graphics page)
	{
		page.drawRect (50, 50, 40, 40);		//square
		page.drawRect (60, 80, 225, 30); 	//rectangle
		page.drawOval (75, 65, 20, 20); 	//circle
		page.drawLine (35, 60, 100, 120); 	//line
		
		page.drawString ("Out of clutter, find simplicity.", 110, 70);
		page.drawString ("-- Albert Einstein", 130, 100);
	}
}

The software I'm using is TextMate 1.5.7
The example in the book shows Windows screen, but I haven't been told otherwise than it is fine for me to use a mac, but still I can't get this to run and I'm pretty sure I've copied the code exactly from the book.

Could someone please advice me or tell me if/what I'm doing wrong here? Or if I am missing some additional software that I need?
(My apologies for poor grammar, English ain't my first language.)

Thanks in advance!

First you need to read the rules and then you need to seriously learn the basics of Java, which you can start with the first thread titled "Starting Java"

And if you are a beginner in Java why are you starting directly with graphical user interfaces and applets, first learn to write some console based programs and then gradually as you get a good grasp of the language move ahead to slightly more advanced topics like applets and swings.

You do not start to learn swimming by diving in the middle of the ocean straight away.

If you copied that directly from a textbook, you need to throw it in the garbage. Not one of the declarations (import, class, and method) is correct.

This is copied directly from my textbook, yes. Then there might not be a big wonder if I can't get this thing to work, if the code is all wrong. Must be a mistake in the book then.


And to stephen84s, this is actually an example in just 2nd chapter of the book, I can't really do much about what the teacher is telling us to do and read :-p I'm not personally trying to rush into anything. And thanks for those links, I'll check them out.

Well, it's very odd that all of the keywords like import, public, void, implements, class, etc. are missing from the code.

Yes, odd indeed, but I've copied alot of other codes from it that work fine. This one must have gone wrong somehow. It's here 100% like it is in the book.
Still doesn't matter, I've gotten the answer to my question in that case; TextMate is working fine, it's the code that is wrong.

This article has been dead for over six months. Start a new discussion instead.