Want help in implement this thread in java applet.

Morningdot Hablu

Morningdot Hablu

@morningdot-6Xuj4M Oct 26, 2024
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.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Aug 31, 2010

    Are you facing difficulty in above code?
  • Morningdot Hablu

    Morningdot Hablu

    @morningdot-6Xuj4M Aug 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.