Solved

AppletContext sample

Posted on 2000-02-23
6
758 Views
Last Modified: 2006-11-17
Anyone out there have an example of an applet which uses the AppletContext stuff to load a URL into a new browser window? I've been banging my head against this to no avail and would like to see some source from someone who has either done it or has one of those phone-book size Java manuals with a handy example to plagiarize.

100 points for a quick sample.


TIA

Marty
0
Comment
Question by:mravell
6 Comments
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2551652
getAppletContext().showDocument(url, "XXX")

Here xxx is the target frame.
Since there is no frame at all, it will open a new window

url is the url U have to give in the format

http://yourserver:serverport/file
0
 

Author Comment

by:mravell
ID: 2552173
Hi Ravindra,

Can you post some actual applet code? I got this much from the Java Doc already.

Do I have to implement the AppletContext interface or something?

Some actual working source is what I'm really after. Please assume ignorance on my part!



Regards
M
0
 
LVL 8

Expert Comment

by:diakov
ID: 2552293
If your program is an applet, it already has a valid AppletContext and ravindra76's example is actually a piece of code.

Cheers,
  Nik
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Accepted Solution

by:
muraliram earned 100 total points
ID: 2553461
Dear friend,


if(e.getSource()==b1)
{
try{
URL url=new URL("http://www.yoursite.com/your.html");
}
catch(MalformedURLException e){}
getAppletContext().showDocument(url,"_blank");
}
will work properly
Don't forget to modify the code as per your need.
0
 
LVL 1

Expert Comment

by:vishone
ID: 2560711

 Hi mravell, Didn't you try the piece of code given by Ravindra?





0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2560875

Run this code as

Jump.html :-

Note: put this jump.html and Jump.class in ur webserver document root.

for me it is http://localhost/jump.html

<HTML><HEAD></HEAD><BODY>
 <APPLET CODE="Jump.class"
         HEIGHT=100
         WIDTH=300>
 </APPLET></BODY></HTML>

Jump.java


import java.awt.*;
import java.applet.*;
import java.net.*;

public class Jump extends Applet {
      Button btnJump;

      public void init() {

            btnJump = new Button("JUMP To");
            add(btnJump);
      }
      public boolean action(Event e,Object o) {

            if ( e.target.equals(btnJump)) {
                  try {
                  getAppletContext().showDocument(new URL("http://www.yahoo.com"),"xxx");
                  }
                  catch ( Exception ee) {
                        System.out.println("Malformed URL");
                  }
            }
            return false;

      }
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

840 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