ok, i have no idea how to add an image to the java applet. I can do it using objectdraw, but my teacher wont let me use objectdraw, so i need to know how to do it with something else. Can someone give me the basic code to add an image to the applet? Ive searched for the code everywhere on google, ask geeves and other tutorials and even other forums. Noone seems to know how.
ok, so i created a new project (a basica java applet) and called it ImageApplet, and then i coppied the exact ImageApplet.java file that you gave me and then i pasted it into the new ImageApplet that i created and replaced the line ------------------------LINE 25-------------------
String imagePath = this.getParameter("Image_path");
to
String imagePath = this.getParameter("RiskBoard800x505.jpg");
----------------------------------------------------------
RiskBoard800x505.jpg is the picture that i want to show up, and i have it stored in the class folder of my projeect. Is this the only line of code that i have to change? If not what else do i have to change and if it is the only line i have to change then why do i get some text when i load the applet saying "Image load failed: null"?
Thanks for the reply, i really appreciate it because, so far you are the only source i have on this information since i couldnt find it anywhere else when i searched.
Line one defined the package; when you compile this source file the class file will
be saved in a folder named stubs6, a subfolder of the source file's folder.
You should not change anything in the code, only the html. The code:
String imagePath = this.getParameter("image_path");
gets the value of the parameter named "image_path", - check the html and set
the value of this parameter to your file name:
To set this up as is you must upload the ImageApplet.html to a folder on your server,
e.g "applets".
Then you must create a subfolder of this names "stubs6", and a folder: "images"
under the stubs6 folder, and upload files like:
...now to draw it to the graphics object (using object graphics g)...
g.drawImage(RiskBoard,200,200,null);
// 200 and 200 are the x and y coordinates
If this is far too simple for what you're doing, my apologies in advance. If its far too advanced, the same. To be honest I've never seen what you're trying to do.
Thanks MikeKomo. Thats perfect. Thats exactly what i wanted. Something really simple. Thank you very much. But now, how do i make this image a button? I need something to happen when the image is clicked. So im assuming that i need to add an action listener to it? But i dont know how to do that..so if u have some free time i would appriciate the extra help. Thanks again.
You must implement the mouselistener interface for the component that you display
your image in, leave all thos methods empty except the mousePressed or the meouseClicked where you dor your stuff.
Bookmarks