Help with image

hi,
Please help me in getting image for the following code.

public class LoadImageAndScale extends JApplet
{
private Image image1;
private ImageIcon image2;

public void init()
{
image1 = getImage( getDocumentBase(), "redflowers.png" );
image2 = new ImageIcon( "yellowflowers.png" );
}


public void paint( Graphics g )
{
super.paint( g );

g.drawImage( image1, 0, 0, this );


g.drawImage( image1, 0, 120, getWidth(), getHeight() - 120, this );

image2.paintIcon( this, g, 180, 0 );
}
}

Here my problem is how to get the image? I have not downloaded the image from the net. But I have downloaded Java How to Programme 6th edition.Where should i save that image and how to access that image here in the getImage() method.

Comments

  • : hi,
    : Please help me in getting image for the following code.
    :
    : public class LoadImageAndScale extends JApplet
    : {
    : private Image image1;
    : private ImageIcon image2;
    :
    : public void init()
    : {
    : image1 = getImage( getDocumentBase(), "redflowers.png" );
    : image2 = new ImageIcon( "yellowflowers.png" );
    : }
    :
    :
    : public void paint( Graphics g )
    : {
    : super.paint( g );
    :
    : g.drawImage( image1, 0, 0, this );
    :
    :
    : g.drawImage( image1, 0, 120, getWidth(), getHeight() - 120, this );
    :
    : image2.paintIcon( this, g, 180, 0 );
    : }
    : }
    :
    : Here my problem is how to get the image? I have not downloaded the image from the net. But I have downloaded Java How to Programme 6th edition.Where should i save that image and how to access that image here in the getImage() method.
    :
    :
    The image should be in the same directory as the class file of the object.
  • : : hi,
    : : Please help me in getting image for the following code.
    : :
    : : public class LoadImageAndScale extends JApplet
    : : {
    : : private Image image1;
    : : private ImageIcon image2;
    : :
    : : public void init()
    : : {
    : : image1 = getImage( getDocumentBase(), "redflowers.png" );
    : : image2 = new ImageIcon( "yellowflowers.png" );
    : : }
    : :
    : :
    : : public void paint( Graphics g )
    : : {
    : : super.paint( g );
    : :
    : : g.drawImage( image1, 0, 0, this );
    : :
    : :
    : : g.drawImage( image1, 0, 120, getWidth(), getHeight() - 120, this );
    : :
    : : image2.paintIcon( this, g, 180, 0 );
    : : }
    : : }
    : :
    : : Here my problem is how to get the image? I have not downloaded the image from the net. But I have downloaded Java How to Programme 6th edition.Where should i save that image and how to access that image here in the getImage() method.
    : :
    : :
    : The image should be in the same directory as the class file of the object.
    :
    hi,
    Tnx for replying,
    but the thing is i'm not getting the image while i'm running this applet through appletviewer/browser. i'm getting an empty box(with out image). Please help me in running the above program.
  • : : : hi,
    : : : Please help me in getting image for the following code.
    : : :
    : : : public class LoadImageAndScale extends JApplet
    : : : {
    : : : private Image image1;
    : : : private ImageIcon image2;
    : : :
    : : : public void init()
    : : : {
    : : : image1 = getImage( getDocumentBase(), "redflowers.png" );
    : : : image2 = new ImageIcon( "yellowflowers.png" );
    : : : }
    : : :
    : : :
    : : : public void paint( Graphics g )
    : : : {
    : : : super.paint( g );
    : : :
    : : : g.drawImage( image1, 0, 0, this );
    : : :
    : : :
    : : : g.drawImage( image1, 0, 120, getWidth(), getHeight() - 120, this );
    : : :
    : : : image2.paintIcon( this, g, 180, 0 );
    : : : }
    : : : }
    : : :
    : : : Here my problem is how to get the image? I have not downloaded the image from the net. But I have downloaded Java How to Programme 6th edition.Where should i save that image and how to access that image here in the getImage() method.
    : : :
    : : :
    : : The image should be in the same directory as the class file of the object.
    : :
    : hi,
    : Tnx for replying,
    : but the thing is i'm not getting the image while i'm running this applet through appletviewer/browser. i'm getting an empty box(with out image). Please help me in running the above program.
    :
    The code itself looks right to me. It appears that the applet cannot find the image. It might help to draw the document base to see where the applet looks for the image.
  • : hi,
    : Please help me in getting image for the following code.
    :
    : public class LoadImageAndScale extends JApplet
    : {
    : private Image image1;
    : private ImageIcon image2;
    :
    : public void init()
    : {
    : image1 = getImage( getDocumentBase(), "redflowers.png" );
    : image2 = new ImageIcon( "yellowflowers.png" );
    : }
    :
    :
    : public void paint( Graphics g )
    : {
    : super.paint( g );
    :
    : g.drawImage( image1, 0, 0, this );
    :
    :
    : g.drawImage( image1, 0, 120, getWidth(), getHeight() - 120, this );
    :
    : image2.paintIcon( this, g, 180, 0 );
    : }
    : }
    :
    : Here my problem is how to get the image? I have not downloaded the image from the net. But I have downloaded Java How to Programme 6th edition.Where should i save that image and how to access that image here in the getImage() method.
    :
    :

    Applets have security features that prevent them from accessing local file systems (so that your computer can't be hacked just by looking at the wrong website etc.) so you'll either need to override the security settings (which I've never been bothered to do), or load your images from URLs.

    Or write it as an application instead of an applet?

    Matty
    matty@i-compute.net
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories