Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loading URL in a frane

Posted on 1997-04-28
3
Medium Priority
?
249 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 100 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…
Suggested Courses

715 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