// SinglePictureApplet.java (c)Kari Laitinen // http://www.naturalprogramming.com/ // 2000-10-21 File created. // 2006-10-21 Last modification. // This program demonstrates how a Java applet can show pictures. // The picture files (e.g. .jpg or .gif) files must be in the same // folder where the Java program (i.e. the .class file) is located. import java.awt.* ; public class SinglePictureApplet extends javax.swing.JApplet { Image picture_to_show ; public void init() { picture_to_show = getImage( getCodeBase(), "governor_arnold_schwarzenegger.jpg" ) ; } public void paint( Graphics graphics ) { super.paint( graphics ) ; int picture_width = picture_to_show.getWidth( this ) ; int picture_height = picture_to_show.getHeight( this ) ; int picture_position_x = 15 ; int picture_position_y = 15 ; // The following statement shows the picture in its natural size. graphics.drawImage( picture_to_show, picture_position_x, picture_position_y, this ) ; picture_position_x = picture_position_x + picture_width + 10 ; // Next we'll show a smaller version of the picture. graphics.drawImage( picture_to_show, picture_position_x, picture_position_y, picture_width / 2, picture_height / 2, this ) ; picture_position_x = picture_position_x + picture_width / 2 + 10 ; // The last statement shows the picture so that its width is enlarged. graphics.drawImage( picture_to_show, picture_position_x, picture_position_y, (int) (picture_width * 1.5), picture_height, this ) ; } }