Solved

Loading URL in a frane

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
by zero exception 10 83
ejb example issues 3 89
Tagging and Merging on Branch 1 69
Java regex 5 22
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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:
Suggested Courses

739 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