import java.awt.Graphics; import javax.swing.JFrame; class node{ node(int a,node next){ this.a=a;this.next=next; } int a; node next; } public class df extends JFrame implements Runnable{ Thread t; node p,q; node First; public df(){ t=new Thread(this); p=new node(1,null); First=p; q=p; p=new node(2,null); q.next=p; q=p; p=new node(3,null); q.next=p; q=p; p=new node(4,null); q.next=p; q=p; p=new node(5,null); q.next=p; q=p; t.start(); } public void run() { p = First; while (p != null) { try { repaint(); t.sleep(1000); } catch (Exception e) { } p=p.next; } } public void paint(Graphics g){ System.out.println(p.a); } public static void main(String[]as) { new df(); } }
The code was ran not right, I want it's result is: 1 2 3 4 5 and delay(1000) every time that it prints a number
exemple: 1 (delay(1000)) 2 (delay(1000)) ....
and the paint must do that
please help me!