Solved

AppletContext sample

Posted on 2000-02-23
6
755 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now