Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-03-2008, 01:28 AM
Member
 
Join Date: Aug 2008
Posts: 1
kapil_ghai2003 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-03-2008, 02:03 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-03-2008, 08:16 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have to explain your question in more details. Mainly the way you want to end-up with those threads and so on.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 08:12 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org