|
mutlithreading problem
hi guy's
plz check my code i have create three thread in my code but their only one thread working
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class data extends JApplet implements Runnable
{
JPanel p1,p2;
Date d1;
GregorianCalendar gc;
JLabel l1,l2;
Icon co[];
Thread t1,t2,t3;
String s1, s2, s3;
String c[]={"india","pakistan"};
int count,count1;
public data()
{
p1= new JPanel();
getContentPane().add(p1);
p2= new JPanel();
p1.setLayout(null);
l1 = new JLabel("");
l1.setBounds(10,10,200,200);
p1.add(p2);
p2.setBounds(10,300,200,200);
l2 = new JLabel("");
l1.setBounds(10,10,200,200);
co = new Icon[4];
co[0] = new ImageIcon("D:\\SNAPS\\100_0432.jpg");
co[1] = new ImageIcon("D:\\SNAPS\\100_0430.jpg");
co[2] = new ImageIcon("D:\\SNAPS\\100_0431.jpg");
p1.add(l1);
p2.add(l2);
t1 = new Thread(this);
t2 = new Thread(this);
t3 = new Thread(this);
t1.start();
t2.start();
t3.start();
}
public void run()
{
while(t1 != null)
{
dis();
try
{
t1.sleep(1000);
}
catch(Exception ex)
{
showStatus("Error");
}
}
while(t2 != null)
{
dis1();
try
{
t2.sleep(1000);
}
catch(Exception ex)
{
showStatus("Error");
}
while(t3 != null)
{
dis2();
try
{
t3.sleep(1000);
}
catch(Exception ex)
{
showStatus("Error");
}
}
}
}
public void dis()
{
d1 = new Date();
gc = new GregorianCalendar();
gc.setTime(d1);
s1 = gc.get(Calendar.MONTH+1 )+ " / " +gc.get(Calendar.DATE )+ " / "
+gc.get(Calendar.YEAR);
s2 = gc.get(Calendar.HOUR)+ " : " +gc.get(Calendar.MINUTE)+ " / "
+gc.get(Calendar.SECOND);
s3 = s1+" "+s2;
showStatus(s3);
}
public void dis1()
{
l2.setText(c[count]);
count++;
if(count>1)
count=0;
}
public void dis2()
{
l1.setIcon(co[count1]);
count1++;
if(count1>2)
count1=0;
}
}
//<applet code = data.class height = 1000 width =1000></applet>
so plz solve my this problem]
thanx in advnace
|