Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

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.

                         

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

Latest Searches:
user login servletsusi
login session servlet
dynamically Textbox ar
javamail with files at
Java and JSF database
edit jsp mysql jsp
video player in java a
java / menu bar
primitive data types u
equilateral triangle p
calculate mode in Java
PHP User Authenticatio
how to change url
average numbers
Jigloo SWT/Swing GUI B
string programe in jav
video upload Bea Weblo
Javascript Date and Ti
jasper report
bean struts tag
add a list box in a fo
jsf tree node set hr
Javascript Links and B
source code of sale
simple calculator prog
drow arc
Java Count Vowels in t
covert uppercase to lo
GUIThread
JavaFX 3D Effect Examp
pattern
activate
jsf custom tags
compound interest prog
poi-bin-3.1-beta2-200
how to print arraylist
pb tree implementati
CVS
stored
cgi
tree and treenode (Aja
format a number decima
jstl if
how to manipulate mand
how to split string c
compress file uploadin
create xls using POI
mysql-connector-java-3
stopping action event
StringTokenizer select
prime numbers between
JScrollPane
authentication jsf
linked list and window
hash table mapping
java udp
insert data to databas
explanation
Error handling in stru
JSF panelGrid render
insert into
fibonacci method
jcreator code of calcu
tree
session destroy
jtabel
how to use tab control
java random numbers
ftp
Package Examples
J2ME Gauge
multiple rows in singl
Time
flex struts
how to user JSpinner t
convert text file to i
sorting with dropdown
creating exception exa
html:img
goto
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.