473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Loading Image in An Applet

Hello

I am trying to do a simple java applet which loads image from a specified url.

Here is the code I have now, but it cant seem to work.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.applet.*;
  3. import java.awt.*;
  4.  
  5. public class ATestofLoadImage extends Applet {
  6.  
  7.     Image image;
  8.     public void init() {
  9.         // Load image
  10.         image = getImage(getDocumentBase(), "http://127.0.0.1:8550/epe/map/render?name=Tag%201");
  11.     }
  12.     public void paint(Graphics g) {
  13.         // Draw image
  14.         g.drawImage(image, 0, 0, this);
  15.     }
  16. }
  17.  
  18.  
When i compiled the program, there was no errors, but the applet doesnt load the image. The URL specified is correct; it can be loaded in the web browser.
What might be the problem?

Thank you for your help.
Aug 10 '07 #1
2 2328
praveen2gupta
201 100+
Hello

I am trying to do a simple java applet which loads image from a specified url.

Here is the code I have now, but it cant seem to work.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.applet.*;
  3. import java.awt.*;
  4.  
  5. public class ATestofLoadImage extends Applet {
  6.  
  7.     Image image;
  8.     public void init() {
  9.         // Load image
  10.         image = getImage(getDocumentBase(), "http://127.0.0.1:8550/epe/map/render?name=Tag%201");
  11.     }
  12.     public void paint(Graphics g) {
  13.         // Draw image
  14.         g.drawImage(image, 0, 0, this);
  15.     }
  16. }
  17.  
  18.  
When i compiled the program, there was no errors, but the applet doesnt load the image. The URL specified is correct; it can be loaded in the web browser.
What might be the problem?

Thank you for your help.
Hi
There are two problems
1. use applet tag before the class name
ex.
Expand|Select|Wrap|Line Numbers
  1.  /*
  2.  <applet code="ATestofLoadImage" height="500" width="500">
  3.  </applet>
  4.  */
  5.  
2. Test your URL in the browser first then apply in the code. It seems that Your url is not working. http://127.0.0.1:8550/epe/map/render?name=Tag%201

if you are getting the image in the browser then will will also be getting it in the applet.
Aug 10 '07 #2
JosAH
11,448 Expert 8TB
Hello

I am trying to do a simple java applet which loads image from a specified url.

Here is the code I have now, but it cant seem to work.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.applet.*;
  3. import java.awt.*;
  4.  
  5. public class ATestofLoadImage extends Applet {
  6.  
  7.     Image image;
  8.     public void init() {
  9.         // Load image
  10.         image = getImage(getDocumentBase(), "http://127.0.0.1:8550/epe/map/render?name=Tag%201");
  11.     }
  12.     public void paint(Graphics g) {
  13.         // Draw image
  14.         g.drawImage(image, 0, 0, this);
  15.     }
  16. }
  17.  
  18.  
When i compiled the program, there was no errors, but the applet doesnt load the image. The URL specified is correct; it can be loaded in the web browser.
What might be the problem?

Thank you for your help.
Only the first argument is supposed to represent a URL; the second parameter
is just the name of the image. You could just use the second parameter only.
Read the API documents for the Applet class to see the exact meaning of both
parameters.

kind regards,

Jos
Aug 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Doug van Vianen | last post by:
Although I have programmed for several decades I am new to Java. I decided to learn it to create Applets to use in web pages I make as a volunteer in the computer club at a seniors' centre. My...
2
by: Mark Richards | last post by:
An applet on one of my pages uses a big picture as background. I want to load it before the applet and the rest of the html source. By doing this I want to avoid that the pane of the applet is...
3
by: Jacques Chaurette | last post by:
Hello all , thanks in advance for any help. While looking for a solution to how to replace the grey box while an applet loads, a search of Google got me an article by Glenn s. Peffers that claims to...
1
by: Alixx Skevington | last post by:
I want to be able to have a page that has several controls on on it, but I want the page to load first of all and display a loading image on each control and then I want to then display teh...
0
by: UnkleVo | last post by:
Hello all, We have a form that contains browser control on it. Into that control we load some java applet that acts as an image viewer. On the form load we load the list of documents each with...
9
by: takeiteasy | last post by:
Hello everyone, I've got a question about programming by using Java applet and the question is : Design a web page containing an applet that simply switches from one image to the next with some...
0
by: speedcoder | last post by:
hi all, i'm stumped. my applet used to load images over the network. (it was actually designed by someone else.) yes, the applet used to load each image file independently over the network and...
1
by: rajbala.3399 | last post by:
Hi all, I have the netbeans IDE5.5 in my system and redhat9.While i run my plugin or beans program in JSP the output you see an image that looks like a small white box with a Red X in it. Or, the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.