Solved

Loading URL in a frane

Posted on 1997-04-28
3
202 Views
Last Modified: 2010-04-16
I'm new at Java.  How do I load a URL into a frame?
0
Comment
Question by:Evil
3 Comments
 
LVL 6

Expert Comment

by:jpk041897
Comment Utility
Could you be more specific?

Do you mean the contents of a file, an HTTP page or an image (gif or jpeg)

If http, do you just want straight text or do you want to simulate browser behaviour?

For instance, to read the contents of a file:

1.- Define the address (getCodeBase() uses the directory where the applet was loaded from as root)

String url = "http://" + getCodeBase().getHost() + "/file.dat";

2.- Define an Input (or output) stream and a buffer for the data . For instance:
             

DataInputStream data;
String line;
              
Instantiate a URL member and asign it to whatever type of I/O operation you need. Example:

try{
   try{
     URL theURL = new URL("http", getCodeBase().getHost(), 80, "/rooms.dat");
      data = new DataInputStream(new BufferedInputStream( theURL.openStream()));
       while ((line = data.readLine()) != null) {
           // do whatever you want with the info
           YourTexttArea.appendText(line); //(append without Text for 1.1)
   }                          }
   }catch( MalformedURLException e ) {
   // Do what you want with wrong address error here
                    }
}catch (IOException e) {
// Hande I/O error here.                    
}

Other types of files/behaviour will require additional work.
0
 

Author Comment

by:Evil
Comment Utility
I mean loading a HTML page.  Like if you clicked on a regular link.
0
 
LVL 1

Accepted Solution

by:
toml032697 earned 50 total points
Comment Utility
You can load the HTML page with showDocument() method. To load a HTML page into a specific frame you must give the name of the frame as a parameter. Here is a small example:

getAppletContext.showDocument(new   URL(getCodeBase()+"my_page.html",target);

target is a string which contains the name of the frame or window into which you want my_page.html to be loaded into.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 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

17 Experts available now in Live!

Get 1:1 Help Now