The Java Programming Language

Lamp Example Program


Click below to go directly to a specific section:
Description | Source Code | Sample Run | Program Notes


 

Description

This program demonstrates and power of Java graphics along with their ease of use.


 

Source Code

import java.awt.*;

public class Lamp extends java.applet.Applet {

    public void paint(Graphics g) {
        // lamp platform
        g.fillRect(0,250,290,290);

        //lamp base
        g.drawLine(125,250,125,160);
        g.drawLine(175,250,175,160);

        //lamp shade (top and bottom edges)
        g.drawArc(85,157,130,50,-65,312);
        g.drawArc(85,87,130,50,62,58);

        //lamp shade (sides)
        g.drawLine(85,177,119,89);
        g.drawLine(215,177,181,89);

        //dots on shade
        g.fillArc(78,120,40,40,63,-174);
        g.fillOval(120,96,40,40);
        g.fillArc(173,100,40,40,110,180);
    }
}

 

Sample run



 


Program Notes

This program was compiled and run using the Java Developers Kit, Version 1.2.1 for Win32 on x86 from Sun Microsystems running under Windows 98.


[Back] [Home]

 

Last modified: 09:55 PM on 11/14/1999