CrazyEngineers
  • Want help in implement this thread in java applet.

    Updated: Oct 26, 2024
    Views: 946
    Hello friends,
    I try to write a program for stop watch with the help of applet(not swing) and thread.
    I completed to make the thread for this
    check out this code
    import java.awt.*;
    import java.applet.*;
    /*<APPLET CODE="r.class" HEIGHT=200 WIDTH=300></APPLET>*/
    public class r
    {
    public static void display(int x)
    {

    String z=Integer.toString(x);
    //return(z);
    System.out.println(z);
    }
    //public void paint(Graphics g,String f)
    //{
    //g.drawString(f,20,40);
    //}
    public static void main(String args[])
    {
    r g=new r();
    int x=0;
    Thread t=new Thread();
    t.start();
    while(t!=null)
    {
    try
    {
    r.display(x);
    //this.paint();
    t.sleep(1000);
    x++;
    }
    catch(InterruptedException e)
    {
    System.out.println("Thread interrupted ");
    }
    }
    }
    }
    I want to implement this in applet.Please help me in doing this in applet.I completed this job in swing but unable to do this in applet.


    Any help will be appreciated.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberAug 31, 2010

    Are you facing difficulty in above code?
    Are you sure? This action cannot be undone.
    Cancel
  • Morningdot Hablu

    MemberAug 31, 2010

    thanks for consider my question goyal....now i solved it.
    I want this one.Check it out.
    .
    import java.awt.*;
    import java.applet.*;
    /*<APPLET CODE="kk.class" HEIGHT=200 WIDTH=300></APPLET>*/
    public class kk extends Applet implements Runnable
    {
    int x=0;
    Thread t;
    public void init()
    {
    setBackground(Color.cyan);
    }

    public void start()
    {
    t=new Thread(this);
    t.start();
    }
    public void run()
    {
    while(t!=null)
    {
    try
    {
    repaint();
    t.sleep(1000);
    x=x+1;
    }
    catch(InterruptedException e)
    {
    System.out.println("Thread interrupted ");
    }
    }
    }
    public void paint(Graphics g)
    {
    String z=Integer.toString(x);
    g.drawString(z,20,40);
    }
    }
    Well it's a simple one.I done a silly mistake.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register