Solved

Loading URL in a frane

Posted on 1997-04-28
3
245 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

626 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