Saturday, April 24, 2010

Another Sample Applet and Graphics

I have previously written a number of posts on Java applets but since are off, I quite miss posting java codes that I use for classroom instruction.

I however, found this simple code on applet and some graphics methods.  The code makes use getImage() and drawImage() to display needed image file on the page. Do check.  This will only run through an applet viewer or an html page to launch the applet-embedded java program.

[+/-] show/hide

import java.awt.*;
/** An applet that draws an image. */
public class JavaJump extends Applet {
private Image jumpingJava; // Instance var declarations here
public void init() { // Initializations here
setFont(new Font("SansSerif", Font.BOLD, 18));
jumpingJava = getImage(getCodeBase(),
add(new Label("Great Jumping Java!"));
System.out.println("Yow! I'm jiving with Java.");
public void paint(Graphics g) { // Drawing here
g.drawImage(jumpingJava, 0, 50, this);

No comments: