Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Problem of displays the names of three Internet sites?

  Asked By: Lucas    Date: May 23    Category: Java    Views: 540
  

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();
} }
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Problem of displays the names of three Internet sites? Or get search suggestion and latest updates.




Tagged: