Jump to content

Burning candles Java applet using threads

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Nyfer

Nyfer

    Newbie

  • Members
  • PipPip
  • 19 posts
This is an applet code in which i display 3 burning candles . i have used java threads
Enjoy!!!
Attached File  candle1.png   32.87K   132 downloads


/**

 *

 * @author nyfer

 */

import java.awt.*;

import java.applet.*;

public class Candle extends Applet implements Runnable {

int i=0,j=0,r1=0,r2=0,r3=0,z=0;

         Thread t1=null;

	 boolean threadsuspend;



 [I]  /** Initializes the applet Candle */[/I]

    public void init() {


    }


    public void paint(Graphics g)

    {


	[I]  /**  draw rectangles */[/I]


	    g.setColor(Color.red);

	    g.fillRoundRect(100,100,50,200,20,20);

	    g.setColor(Color.green);

	    g.fillRoundRect(150,120,50,200,20,20);

	    g.setColor(Color.blue);

	    g.fillRoundRect(200,80,50,200,20,20);


	 [I]/**   draw ovals */[/I]


	    g.setColor(Color.yellow);

	    g.fillOval(112,55,25,50*r1/10);

	    g.fillOval(162,75,25,50*r2/10);

	    g.fillOval(212,35,25,50*r3/10);


	  [I] /**  draw lines */[/I]


	    g.setColor(Color.black);

	    g.drawLine(125,100,125,70);

	    g.drawLine(175,120,175,95);

	    g.drawLine(225,80,225,50);


	    g.setColor(Color.green);

	    g.fillOval(180,310,60,10);

	    g.fillOval(125,310,60,10);


	    g.setColor(Color.red);

	    g.fillOval(70,290,60,10);


	    g.setColor(Color.blue);

	    g.fillOval(235,270,60,10);

	    while(z<3 && z>=1)

	     {

	      g.drawOval(249,80*z,10,20);

         }

    }

    public void start()

    {

        if(t1==null)

	      {

	       Thread t1=new Thread(this);

	       threadsuspend=false;

	       t1.start();

          }

    }


    public void run()

    {

        try{

		     while(true){

			         r1=((int)(Math.random()*10));

		             r2=((int)(Math.random()*10));

		             r3=((int)(Math.random()*10));

			         z=((int)(Math.random()*10));



            repaint();

            t1.sleep(100 );

         }

      }

      catch (InterruptedException e) { }

  }

    


    /** This method is called from within the init() method to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          

    private void initComponents() {


        setLayout(new java.awt.BorderLayout());

    }// </editor-fold>                        



    // Variables declaration - do not modify                     

    // End of variables declaration                   


}



Thank you

Attached Files



#2
redwee

redwee

    Newbie

  • Members
  • Pip
  • 1 posts
Hi Nyfer!
Thanks very much for sharing them.

#3
Nyfer

Nyfer

    Newbie

  • Members
  • PipPip
  • 19 posts
Sure, ur welcome :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users