Java Code
/** Example showing drawing methods overlapping
* @author : E.S.Boese
* @version: Fall 2008
*/
import java.awt.*;
import javax.swing.*;
public class DrawOnImage extends JApplet
{
public void paint( Graphics g )
{
super.paint( g );
Image breakfast = getImage( getCodeBase( ), "China_Foods.jpg" );
g.drawImage( breakfast, 0,0, this );
Font bold16font = new Font( "Serif", Font.BOLD, 16 ); //text font
g.setFont( bold16font );
g.setColor( Color.green ); // eggs
g.drawOval( 21, 180, 40, 40 );
g.drawOval( 22, 181, 38, 38 ); // thicken the drawing
g.drawLine( 42, 180, 50, 95 ); // line from eggs
g.drawString( "Eggs for breakfast", 50, 95 ); // pointing to eggs
g.setColor( Color.blue ); // noodles
g.drawOval( 35, 245, 90, 75 );
g.drawLine( 120, 255, 190, 240 );
g.drawString( "Noodles for every meal", 190, 245 );
g.setColor( Color.YELLOW ); // sauces
g.drawRect( 70,180, 90, 40 );
g.drawLine( 115, 180, 130, 145 );
g.drawString( "Amazing sauces", 130, 140 );
}
}
Back to Code Examples
©2006-
by E.S.Boese. All Rights Reserved