Tutorials Point

  Java Basics Examples
  Java Tutorial
  Java Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Java Examples - open link in a new window using an Applet

previous next AddThis Social Bookmark Button

Problem Description:

How to open a link in a new window using Applet?


Following example demonstrates how to go 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.net.*;
import java.awt.event.*;

public class testURL_NewWindow 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){


The above code sample will produce the following result in a java enabled web browser.

View in Browser. 

previous next Printer Friendly



Online Image Processing

Indian Baby Names