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

Opening a URL from an Applet

                         

Introduction

This is the example of opening a url in same window from an applet. This program shows that how a url is opened in same document or browser window.

In this program you will see that many features have been used for opening url from an applet. This program is using two functions in which one is init() and another is actionPerformed(ActionListener ae). Function init() is self executed when the program is loaded on the browser. In the init() function a button labeled "Google" is created and it's action is performed using the statement b.addActionListener(this) which passes the object. And all the actions are performed in the another one function actionPerformed(ActionEvent ae) which gets the object ae of the ActionEvent class. Object ae tells you about the source of the event through ae.getSource() which is stored in the Button type source variable after changing the type of the retrieved event-source object and source.getLabel() gives you the caption of the button.

AppletContext has been used in this program. In fact AppletContext is the interface defines the methods, that allow an applet to interact with the context in which it runs (which is usually a Web browser or an applet viewer). And getAppletContext() is used to the reference for the AppletContext interface. To get the AppletContext of the applet getAppletContext() function can be used. We have used the function  getAppletContext.showDocument(u,"_self") that loads the web page linked to the url. In the first case the applet page will be replaced. In the second case, _self is the target which can be :

  1. "_self"       - show in current frame
  2. "_parent"   - show in parent container
  3. "_top"        - show in topmost frame
  4. "_blank"    - show in a new, top-level window
  5. "string"      - show in a frame with that string name.
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_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 u = new URL(link);
//      a.showDocument(u,"_blank");
//      _blank to open page in new window  
      a.showDocument(u,"_self");
    }
    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

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

All the tutorials and examples are so interesting and easy to learn.But i request you to show all the related and methods of a particulsr class being used in example.Hence,i'll try myself with them.
Thank you so much...........

Posted by sn on Wednesday, 05.14.08 @ 12:00pm | #59775

Latest Searches:
JavaScript functions
break?�¢�????????�
breakå??ç?­?å?????å??ç
java structures
how to create two drop
self-avoiding random w
Get first day of week
filechannel
struts 2 iterator
Multi-tier application
file search in directo
class path
input in array
Photoshop Text Effect
how to use indexof in
Struts HTML EL tags
Java General Java Enca
Configure
how to increase the er
<hx:fileProp
<logic:iterator>
pseudocode of magic sq
ล ยà¸?ฤ??????à¸
FileInputStream
struts2 csv result
Dreamweaver Behaviors
Mysql and jsp
custom tags
how to increase the er
message box display in
jsp MENU SELECT MAKES
java stack
javascript DB servl
Creating Website with
MULTIPLE SELECT COMBO
Very interesting tutor
merging pdf
TextArea Frame in Java
tomcate 5.0 downloadab
utility of collections
arraylist storing mult
dojo spinner
X10 Client and Server
create action listener
Murach ? ????s Beginni
Linux Caixa Mб?а
image type in java
Ã???????Ã??????Ã?????Ã
emailing file in java
how to compare current
numberStringsource
JavaScript functions o
parsing the string/str
<f:facet>tag
PHP Web Traffic Analys
User Registeration pag
how to upload image ur
Java Security A three-
core java
draw circle in C
hast table
csv reader
count the numbet of di
å???å????å????å???å???
sะà¸?ั?ยà¸?ะà¸
line break in javascri
break?ะ�ะ???????
iterator.next
check character/str.ph
interface
Configure jstl in web.
Two Dimensional Array
enterprise portal
add two numbers in jav
major
spring portlet
input two numbers thro
sax tutorial
popup window
Linux Caixa MаÐ??аÐ?
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.