Write a Multithreading program in java to convert smile face into the crying face after 5 seconds and vice versa(Use Applet).

import java.awt.*;
/* <applet code="Smileface.class" height=400 width=350>
</applet> */
public class Smileface extends java.applet.Applet implements Runnable
{
    Thread t;
    int f;
    public void init()
    {
         t=new Thread(this);
         t.start();
          f=0;
    }
 public void run()
    {
       try{
            if (f==0)
            {
                        t.sleep(1000);
                        f=1;
                        repaint();
            }
            else
            {
                        t.sleep(1000);
                        repaint();
                        f=0;
            }
            }catch(Exception e){ }
            run();
       }
    public void paint(Graphics g)
    {
        g.drawOval(100,100,100,100);
        g.fillOval(120,125,20,20);
        g.fillOval(160,125,20,20);
        g.drawLine(150,125,150,150);
        if (f==0) {
                         g.drawArc(130,135,40,40,0,-180);
                        f=1;
                       }
            else
                      {
                        g.drawArc(130,170,40,40,0,180);
                        f=0;
                       }
     }
}

Comments

Post a Comment

Popular posts from this blog

Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a record in it.

Create a JSP page to accept a number from an user and display it in words: Example: 123 – One Two Three. The output should be in red color.

Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it into database and display it in tabular form. (Use PreparedStatement interface)