Page 1 of 1

Unable to Get Picture to Appear in Applet upon Running

Posted: Tue Sep 02, 2008 4:48 pm
by vajrapani
According to my text, this example should show a picture of a smile in the upper left corner. However when I run the Applet, the picture doesn't show. Does anyone have any suggestions?



/*
Chapter 2: Welcome to My Day
Programmer: Lori Macdonald
Date: September 2, 2008
Filename: WelcomeApplet.java
Purpose: This project displays a welcome message, the user's name, and the system date in an applet.
*/

import java.util.Date;
import java.awt.*;
import java.applet.*;

public class WelcomeApplet extends Applet

{
public void paint(Graphics g)
{
Date currentDate = new Date(); // Date constructor
g.drawString("Welcome to My Day!",200,70);
g.drawString("Daily planner for Lori Macdonald",200,100);
g.drawString(currentDate.toString(),200,130);
Image smile; // declare an Image Object
smile = getImage(getDocumentBase(), "Smile.gif");
g.drawImage(smile,10,10,this);
setBackground(Color.yellow);
}
}

change method call order...

Posted: Sat Sep 06, 2008 3:18 pm
by Nicholas Jordan
picture is painted then we setBackground, must happen other way probably.

Set background, draw picture. Should happen that way anyway.