adsense


Showing posts with label JAVA EXAMPLES GO TO A LINK USING AN APPLET. Show all posts
Showing posts with label JAVA EXAMPLES GO TO A LINK USING AN APPLET. Show all posts

Monday, 2 November 2015

JAVA EXAMPLES GO TO A LINK USING AN APPLET PAGE 203

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES GO TO A LINK USING AN APPLET






Java Examples - Go to a link using an Applet



Problem Description:
How to goto a link using Applet?
Solution:
Following example demonstrates how to go to a particular webpage from an applet using showDocument() method of AppletContext class.
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;

public class tesURL extends Applet implements ActionListener{
   public void init(){
      String link = "yahoo";
      Button b = new Button(link);
      b.addActionListener(this);
      add(b);
   }
   public void actionPerformed(ActionEvent ae){
      Button src = (Button)ae.getSource();
      String link = "http://www."+src.getLabel()+".com";
      try{
         AppletContext a = getAppletContext();
         URL u = new URL(link);
         a.showDocument(u,"_self");
      }
      catch (MalformedURLException e){
         System.out.println(e.getMessage());
      }
   }
}
Result:
The above code sample will produce the following result in a java enabled web browser.
View in Browser.