patonb
Golden Master
- Messages
- 9,748
- Location
- In Gov't Regulated Cubical
Okay, anyone know if there is a difference in Syntax between 1.02 and 1.5.0_7??
Reason, I've transcride verbatem code from a book and am getting odd errors of;
Code:
Reason, I've transcride verbatem 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.*;
public class ButtonLink extends java.applet.Applet {
Bookmark bmlist[] =new Bookmark[3];
public void 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.name));
}
}
public boolean action(Event evt, Object arg){
if (evt.target instanceof Button){
Linkto((String)arg);
return true;
}else return false;
}
void Linkto(String name){
URL theURL = null;
for(int i=0;i<bmlist.length;i++);{
if(name.equals(bmlist.name))
theURL = bmlist.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