Thursday, 26 October 2023

Write an applet application to display Table lamp. The color of lamp should get change randomly

Write an applet application to display Table lamp.The color of lamp should get change randomly

 import java.applet.*;

 import java.awt.*;

  

public class Lamp extends java.applet.Applet {

   public void init() {

     resize(300,300);

   }

     

  public void paint(Graphics g) {

     // the platform

     g.fillRect(0,250,290,290);

     // the base of the lamp

     g.drawLine(125,250,125,160);

     g.drawLine(175,250,175,160);

 

    // the lamp shade; two arcs

     g.drawArc(85,157,130,50,-65,312);

     g.drawArc(85,87,130,50,62,58);

     g.drawLine(85,177,119,89);

     g.drawLine(215,177,181,89);

 

     // pattern on the shade

     g.fillArc(78,120,40,40,63,-174);

     g.fillOval(120,96,40,40);

     g.fillArc(173,100,40,40,110,180);

   }

 }

 

Lamp.html

<html> 

<body> 

<applet code="Lamp.class" width="300" height="300"> 

</applet> 

</body> 

</html>

  

Output-

 

C:\Program Files\Java\jdk1.7.0_80\bin>javac Lamp.java

C:\Program Files\Java\jdk1.7.0_80\bin>appletviewer Lamp.html