wood burning stoves 2.0*
The moose likes Applets and the fly likes about image. see this simple code please. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "about image. see this simple code please." Watch "about image. see this simple code please." New topic
Author

about image. see this simple code please.

nima lama
Greenhorn

Joined: Jun 18, 2001
Posts: 19
thank you so much the previous reply.
here i have another problem.i wanted to have image img1 as background and img2 as a forground.
at present with the below code, it produces strange result. image img1 come as a background but img2 it does not come on the forground yet it show the space of img2 containing the img1 image.
please help me.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class popo1 extends Applet
{

Image img1,img2;

public void init()
{
MediaTracker mt=new MediaTracker(this);

/*img1 image file is big and covers all the appletspace, where as the
img2 image is small and it should stay like on top of the image img1 file.
in a nutshell..img1 as a background and img2 as forground.
*/
img1=getImage(getDocumentBase(),"d.gif");
img2=getImage(getDocumentBase(),"language.gif");

mt.addImage(img1,1);
mt.addImage(img2,2);

try
{
mt.waitForAll();
}
catch(InterruptedException e)
{}
}
public void paint(Graphics g)
{
g.drawImage(img1,0,0,this);
g.drawImage(img2,20,40,this);
}
}
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I tested this code out with images of my own and it worked perfectly, so it isn't a problem with your code. If you are saying that Image2 doesn't show up at all... that sounds like the image you are specifying doesn't exist... make sure you are spelling "language.gif" correctly ( exactly as the file is named ), and that is it in the same directory with your background image.

HTH,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
nima lama
Greenhorn

Joined: Jun 18, 2001
Posts: 19
respected Nathan,
with reference to my code at above.
if
*******
public void paint(Graphics g)
{
g.drawImage(img1,0,0,this);
g.drawImage(img2,0,0,this);
}
******
then what would be the result.
img2 should come on top of the img1 but it is not coming..
please, tell me.
[This message has been edited by nima lama (edited June 21, 2001).]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

When I run your code, I see img2 drawn on top of img1, just as you would expect. If I go back into the code and change the filename of the image I am trying to load into img2, then I only get img1 loaded, with no img2 painted on top. This is why I advised you to check your image files, because the code is fine.

-Nate
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: about image. see this simple code please.
 
Similar Threads
Building a splash screen
awt
Creating Java applet
Randomly displaying images from a directory with JavaScript?
Simple Thread with image..