Solved

AppletContext sample

Posted on 2000-02-23
6
765 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
[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
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

630 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