View Single Post
Old 08-22-2006, 04:36 PM   #1 (permalink)
patonb
patonb's Avatar
 
Master Techie

Join Date: Jan 2005

Location: In Gov't Regulated Cubical

Posts: 2,765

patonb has a spectacular aura aboutpatonb has a spectacular aura about

Default Ahhhhhhhhh... I'ma hate'n da Java Maan

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;
Quote:
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:

Quote:
// 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[i].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[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


patonb is offline