I have created a applet program that should display the name of
three Internet sites and allows selection of one of these sites using
buttons. But when I run throught appletviewer or IE, it won't
initialise it!! So what can I do? Here is the code I wrote and hope
that would help:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
public class j23a extends Applet {
String Msg = null;
public void init() { //initialise the applet
add(new Button("JavaSoft")); }
void linkTo() {
URL theURL=null;
String urlString = "http://www.javasoft.com/";
try{
theURL= new URL(urlString); }
catch(MalformedURLException e) {
System.out.println("sorry bad URL:"+urlString);}
if(theURL!=null)
getAppletContext().showDocument(theURL); }
public boolean action(Event event, Object object) {
if(event.target instanceof Button) { Msg=(String) object; repaint(); }
return(true); }
public void paint(Graphics g) {
if(Msg != null)
{ g.drawString("Button:" +Msg,30,80);
if(Msg =="JavaSoft")linkTo();
} }
}