Solved

Loading URL in a frane

Posted on 1997-04-28
3
235 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
ID: 1219944
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
ID: 1219945
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
ID: 1219946
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
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 …
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…
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 …

820 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