Login    New User    Forgot Password    Help      

Java Image

Java Tutorials

Images Example

// Images

import java.awt.Graphics;
import java.awt.Image;
import java.applet.*;

public class app11 extends Applet
{

Image img;
public void init()
{
img = getImage(getCodeBase() , "image11.gif");
// img = getImage(getCodeBase() , "images/ladybug.gif");
}

public void paint(Graphics g)
{
int iwidth = img.getWidth(this);
int iheight = img.getHeight(this);
int xpos = 10;

// 25 %
g.drawImage(img, xpos, 10, iwidth / 4, iheight / 4, this);

// 50 %
xpos += (iwidth / 4) + 10;
g.drawImage(img, xpos , 10, iwidth / 2, iheight / 2, this);

// 100%
xpos += (iwidth / 2) + 10;
g.drawImage(img, xpos, 10, this);

// 150% x, 25% y
g.drawImage(img, 10, iheight + 30,
(int)(iwidth * 1.5), iheight / 4, this);

}
}

Output

Output in Applet

Java Tutorials