Solved

open a new browser window with applet

Posted on 2000-04-26
4
247 Views
Last Modified: 2008-02-01
How to create and open a new browser window with an applet?? Is there any method to do this in Java or must it go together with Java Script? Also, if it is possible to open a new window - how to send it HTML code? Please explain how it works with applet calling Java Script - if it is only solution !!
0
Comment
Question by:my_moon011000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 2750983
getAppletContext().showDocument(url);

- Interface java.applet.AppletContext -

 public abstract void showDocument(URL url)

Replaces the Web page currently being viewed with the given URL. This method may be ignored by applet contexts that are not browsers.

Parameters:

url - an absolute URL giving the location of the document.


 public abstract void showDocument(URL url,                                   String target)

Requests that the browser or applet viewer show the Web page indicated by the url argument. The target argument indicates in which HTML frame the document is to be displayed. The target argument is interpreted as follows:


"_self"       Show in the window and frame that contain the applet.
"_parent"      Show in the applet's parent frame. If the applet's frame has no parent frame, acts the same as "_self".
"_top"       Show in the top-level frame of the applet's window. If the applet's frame is the top-level frame, acts the same as "_self".
"_blank"       Show in a new, unnamed top-level window.
name      Show in the frame or window named name. If a target named name does not already exist, a new top-level window with the specified name is created, and the document is shown there.
An applet viewer or browser is free to ignore showDocument.

Parameters:

url - an absolute URL giving the location of the document.
target - a String indicating where to display the page.
0
 

Accepted Solution

by:
snataraj earned 200 total points
ID: 2751058
hi,
   There exists one method in the appletContext class, which loads a given URL in the frame specified. The method is called "showDocument".

I have added a java source which explains the usage. This applet has two buttons , one named yahoo and the other "alta vista". clicking "yahoo" will open yahoo web site in the same window and clicking "alta vista" will open the site in a new window as you are asking for. The second argument in the showDocument function determines the frame in which the specified URL has to be loaded. If you see the code, you can understand it easily.


/*********************start of code*/
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.*;



public class Hyperlink extends Applet implements ActionListener{

      AppletContext      holder;            //appletcontext of the parent applet
      Button             bself,bnew;


      public void init()
      {
            bself = new Button("Yahoo");
            bnew = new Button("Alta vista");
            add(bself);
            add(bnew);
            bself.addActionListener(this);
            bnew.addActionListener(this);
      }

      public void actionPerformed(ActionEvent ae)
      {

            if(ae.getSource() == bself)
            {      try{
                        getAppletContext().showDocument(new URL("http://www.yahoo.com"),"_self");
                  }catch(MalformedURLException me){};            
            }
      
            if(ae.getSource() == bnew)
            {      try{
                        getAppletContext().showDocument(new URL("http://www.altavista.com"),"_blank");
//here "_blank" specifies to open the URL in a new browser window. This is the one you are asking for. YOu can even give the name of any frame, if you have one in the HTML page.


                  }catch(MalformedURLException me){};            
            }

      }

}      

regards
sankar
0
 
LVL 1

Author Comment

by:my_moon011000
ID: 2787938
Thanks, I needed some code !
0
 

Expert Comment

by:snataraj
ID: 2787973
dear my moon,
              Thanks for the acceptance.

all the best
sankar
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java: anonymous class 4 52
Delphi Firemonkey: if the Sms contain special characters it won't send it 3 81
Java array 21 148
Java List 4 74
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question