473,770 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading Image in An Applet

3 New Member
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 2343
praveen2gupta
201 New Member
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 Recognized Expert MVP
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
2763
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 current learning project is to divide a picture into rows and columns of squares, then redisplay the picture with these squares positioned randomly in the rows and columns. In an applet I have stored the original picture as an image, divided it...
2
2524
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 grey during the load of the picture. How do I do that? Or even better: How can I display something like a progress bar or at least a temporary, self removing message (dialog) "Please wait a few second..." until the picture and the applet were...
3
3280
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 solve the problem. You can find the article at http://www.codeproject.com/java/javaappletwaitmsg.asp I have adapted the code to my situation but can't get it to work. Maybe someone has an idea how to fix it... Here is the code Cheers, Jacques...
1
3417
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 controls as the data has bound to each control as some of the data I need to load is very big and takes some time. I have found some code that creates a Javascript that handles this, but it only works at page level. I have looked at the ATLAS...
0
975
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 it's own URL that is pointing to the doc location.When you click on the item in the list it loads the document from the url that this item points to. Problem is that when java applet loads the first time it takes forever.
9
3238
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 transition effects such as : Fade: Fade one image out while you fade the next one in. Whirlpool fade: Building on the fade transition, rather than just fading between images the first image swirls out of focus; the swirl is then reversed and...
0
2204
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 incurred a network hit per image file. i wanted to avoid the overhead of a separate network connection for each image file, so i bundled all the images into the JAR file. yet, somehow, the loading time for the applet is slower now! i'm totally...
1
2780
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 browser cannot display the chat applet, and shows the error message "Loading Java Applet Failed...". I gone through the below sites and i tried each and every thing but it didn't work not only this no. of site to get solve but no use.
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.