Friday, June 11, 2021

JAVA PROGRAM FOR LIGHTING BULB

//~~~~~~~~~~~LIGHTING BULB~~~~~~~~~~~~~//

import  java.awt.*;

import java.applet.*;

/*<applet code=n1.class

         height=300

         width=600>

         </applet>*/

public   class   n1  extends  Applet implements  Runnable

     {

     Thread  t,t1;

     String  msg="lighting  bulb";

     boolean  stop;

     public void init()

     {

     setBackground(Color.GREEN);

     setForeground(Color.YELLOW);

     }

     public void start()

     {

     t=new Thread(this);

     t.start();

     t1=new Thread(this);

     t1.start();

     }

     public  void paint (Graphics  g)

     {

      g.fillOval(120,150,80,100);

      g.fillOval(280,150,80,100);

      g.drawString(msg,200,340);

     }

     public  void  run()

     {

     for(; ;)

     {

     try

        {

          repaint();

          t.sleep(50);

          t.setPriority(10);

          t1.sleep(25);

          t1.setPriority(4);     

        }

          catch(InterruptedException  e){}

     }

     }

}

No comments:

Post a Comment