Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Java - Opening a url in new window from an applet 
 

In this example you will learn how to open a new window from an applet. You can use the code given in this program to open any url by replacing the value of url.

 

Java - Opening a url in new window from an applet

                         

Introduction

In this example you will learn how to open a new window from an applet. You can use the code given in this program to open any url by replacing the value of url.

In this example our applet will open new browser window and then show you the web page. Opening a new window from applet is rather very simple task as all the necessary functions are already available.

When you click the button "google" button on the applet, new browser window will open displaying the specified url, in our case url is http://www.google.com. This is accomplished by specifying the target as " _blank" while calling getAppletContext.showDocument(url, target) function.

Here is the code of the program : 

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);
      b.addActionListener(this);
      add(b);
  }

  public void actionPerformed(ActionEvent ae){
    //get the button label
    Button source = (Button)ae.getSource();
    String link = "http://www."+source.getLabel()+".com";
    try
    {
      AppletContext a = getAppletContext();
      URL url = new URL(link);
      a.showDocument(url,"_blank");
//      a.showDocument(url,"_self");
//      _self to open page in same window  
    }
    catch (MalformedURLException e){
      System.out.println(e.getMessage());
    }
  }
}

Try online this example.

Download this example.

                         

» View all related tutorials
Related Tags: html c com orm air tags sed char tag rounding ai element tar character elements characters like start call cte

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

hi friend.i m harpreet here. i made simple java applet program.i already executed. i wanna to execute this applet on web browser bcoz this applet example was running on separate window.....plz help me

Posted by harpreet on Saturday, 09.20.08 @ 17:45pm | #80572

when I run this applet, I got a non init message on the applet, please help.
boy9983@cup.edu

Posted by Raymond Boyles on Sunday, 03.23.08 @ 21:41pm | #53963

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.