Open a link in a new window using Applet

Open a link in a new window using Applet

Posted in : Core Java Posted on : October 30, 2010 at 6:00 PM Comments : [ 0 ]

This section contains the detail about the Opening a link in a new window using Applet in java.

Open a link in a new window using Applet

Example given in this section demonstrate about how to open a particular webpage from an applet in a new window using showDocument() with second argument as "_blank" :

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class AppletNewWindow extends Applet implements ActionListener{
	public void init(){
	      String link_Text = "google";
	      Button b = new Button(link_Text);
	   public void actionPerformed(ActionEvent ae){
	      Button source = (Button)ae.getSource();
	      String link = "http://www."+source.getLabel()+".com";
	      try {
	         AppletContext a = getAppletContext();
	         URL url = new URL(link);
	      catch (MalformedURLException e){

To embed this code in web browser, we use below html code :
<title>Event Handling</title>
<applet code="AppletNewWindow.class" 
width="500" height="100">

Output :

After opening it in browser :

When we click on button, it will redirect us to "" :

The above screen is captured during page redirecting or before page complete loading.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics