Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    only one thread working
    What is your program supposed to do?
    How do you tell how many threads are working?
    For us to help you to solve this problem, we'll need a bit more information.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •