Beginner Java help.

Okay, anyone know if there is a difference in Syntax between 1.02 and 1.5.0_7?

Reason, I've transcribe this code from a book and am getting odd errors of;

C:\Prog\Java\Day 14\ButtonLink.java:43:'class' or'interface' expected

import java.net.URL;

^

C:\Prog\Java\Day 14\ButtonLink.java:44:'class' or'interface' expected

import java.net.MalformedURLException;

^

2 errors

Tool completed with exit code 1

Code:

// ButtonLink.java starts here

import java.awt.*;

import java.net.*;

publicclass ButtonLinkextends java.applet.Applet{

Bookmark bmlist[] =new Bookmark[3];

publicvoid init(){

bmlist[0] =new Bookmark("Laura's",

"http://www.lne.com/lemay/");

bmlist[1]=new Bookmark("Gamelan",

"http://www.gamelan.com");

bmlist[2]=new Bookmark("Java Home Page",

"http://javasun.com");

setLayout(new GridLayout(bmlist.length, 1,10,10));

for(int i=0;i<bmlist.length; i++);{

add(new Button(bmlist[i].name));

}

}

publicboolean action(Event evt, Object arg){

if (evt.targetinstanceof Button){

Linkto((String)arg);

returntrue;

}elsereturnfalse;

}

void Linkto(String name){

URL theURL =null;

for(int i=0;i<bmlist.length;i++);{

if(name.equals(bmlist[i].name))

theURL = bmlist[i].url;

}

if(theURL !=null)

getAppletContext().showDocument(theURL);

}

}//ends Buttonlink.java

// starts Bookmark.java

import java.net.URL;

import java.net.MalformedURLException;

class Bookmark{

String name;

URL url;

Bookmark(String name, String theURL){

this.name = name;

try{this.url =new URL(theURL);}

catch(MalformedURLException e){

System.out.println("Bad URL: " + theURL);

}

}

}// bookmark ends

I'm teaching myself java, so any and all help's appreciated

THANKS

Message was edited by:

Patonb>

[4329 byte] By [Patonba] at [2007-10-3 3:19:01]
# 1

You cannot embed import statements in the middle of your .java file. All import statements must appear before other code.

(It's better practice to place each class in separate .java files. Had you done so, the import statements would have been correctly placed.)

(Also, this post is more appropriate to the "New to Java" forum.)

ChuckBinga at 2007-7-14 21:10:54 > top of Java-index,Java Essentials,Java Programming...
# 2

Sorry bout the location, noticed after New to java had progamming too.

Now, to the code....... Odd the book does this like that then...

Thanks for the help.

**Edit**

Tried seperating, I think my bookmark class needs to extend from something, but what. I though URL, but no, I was wrong.

Also when I remove bookmark, my "i" variable is no longer recognise.........

Message was edited by:

Patonb

Patonba at 2007-7-14 21:10:54 > top of Java-index,Java Essentials,Java Programming...