Want help in implement this thread in java applet.

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.*;
/**/
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.

Replies

  • Manish Goyal
    Manish Goyal
    Are you facing difficulty in above code?
  • Morningdot Hablu
    Morningdot Hablu
    thanks for consider my question goyal....now i solved it.
    I want this one.Check it out.
    .
    import java.awt.*;
    import java.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.

You are reading an archived discussion.

Related Posts

For which of the following pairs of integers is the least common multiple of the integers minus their greatest common divisor the greatest? A) 3.12 B) 5.6 C) 10.20 D)...
Smith and Jones each had a salary of X dollars a year. Smith's salary was first reduced Y% (0
Hello friends, I have a project to make a music player using java. I completed my half of job.That is i just created a simple music player. Well i started...
Here's a funny video by An Engineering Mind: - [video=youtube;h0ZgED70FMg]https://www.youtube.com/watch?v=h0ZgED70FMg[/video] What do you think?
Here's an interview of Dr. Michio Kaku by An Engineering Mind (National Instruments) - [Note: Must Watch!] Part I - [video=youtube;miAfwJCMRac]https://www.youtube.com/watch?v=miAfwJCMRac[/video] Part II - [video=youtube;X6o_q0NoeNo]https://www.youtube.com/watch?v=X6o_q0NoeNo[/video]