• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

about image. see this simple code please.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
nima lama
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic