Java Code
import java.awt.*;
import javax.swing.*;
public class HouseMethods extends JApplet
{
int WINDOW_WIDTH = 20;
int WINDOW_HEIGHT = 30;
public void paint (Graphics g )
{
super.paint( g );
paintHouse( g );
paintLandscape( g );
}
public void paintHouse( Graphics grph )
{
grph.setColor( Color.pink );
grph.fillRect ( 100,100,200,200 );
grph.setColor( Color.black );
Polygon poly = new Polygon( );
poly.addPoint(100,100);
poly.addPoint(200,50);
poly.addPoint(300,100);
grph.fillPolygon(poly);
grph.setColor( Color.blue );
grph.fillRect ( 200,230,40,70);
// windows
paintWindow( grph, 120, 150 );
paintWindow( grph, 150, 150 );
paintWindow( grph, 200, 150 );
paintWindow( grph, 230, 150 );
}
public void paintWindow(
Graphics gp, int x, int y )
{
gp.setColor( Color.blue );
gp.fillRect( x, y, WINDOW_WIDTH,
WINDOW_HEIGHT);
}
public void paintLandscape( Graphics g )
{
g.setColor( Color.black );
g.fillRect ( 400,130,30,170 );
g.setColor( Color.green );
g.fillOval( 370,80,100,100 );
g.fillRect ( 0,295,500,5 );
}
}
Back to Code Examples
©2006-
by E.S.Boese. All Rights Reserved