DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page Hashtable and JTable Problem
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: May 2008
Default 05-15-2008, 07:00 AM

The problem is something different. Code is runing fine and removing duplicates and showing each ip progress. But now if the same ip has different operation i have to show as a new row in the jtable not taking care of whether the same ip information repeated bcoz i has different operation now. Hope my code is understandable now.

My Jtable looks like
__________________________________________________ _______
ip | operation | progress bar | rate per second | Layer
__________________________________________________ _______

ip's are comming from the network and i am also getting the operations as ARP REQUEST and UDP.

Now there should be separate row for the ip having different operation. I dont know what to change in my hashtable logic but i think i have to compare according to the operation also. Have a look at my code snippet

Code:
public void recieve(String[] a,int nums,int no_of,String udpval)
   {
	 try
	 {				
	 	
		 
	 	ip = a[1];
		
	 	// if ht.get(ip) is return null means counter equal to zero
	 	//if(counter==0)//Is this condition working properly ?.
	 	if(! ht.containsKey(ip))
	 	{
			counter = 1;//counter=counter+1;
			rate = pack_siz;
	 		ht.put(ip,counter);
	 		tabModel.addRow(new Object[]{ip,a[0],counter,createBar(counter, counter+" Packets"),rateBar(rate, rate+" Packets"),udpval});
	 		table.addNotify();
	 		framing.repaint();
	 	}
	 	else//means ht contains the ip, means the table contains the ip/* && ht.containsValue(a[0])*/)
	 	{
		 	counter = Integer.parseInt(String.valueOf(ht.get(ip)));//you need to cast here
		 	rate = pack_siz;
		 	int row_numb = tabModel.getRowCount();
		 	for(int u=0;u<=row_numb-1;u++)
		 	{
			 	if(tabModel.getValueAt(u,0).equals(ip))
			 	{
				 	Object o_val = tabModel.getValueAt(u,2);
				 	++counter;//increment the counter by 1
				 	ht.put(ip,counter);
				 	tabModel.setValueAt(String.valueOf(counter),u,2);
				 	//////////////////////////////////////////
				 	pBar = (JProgressBar)tabModel.getValueAt(u,3);
				 	pBar2 = (JProgressBar)tabModel.getValueAt(u,4);
				 	
					 
				 	if(counter>10)
				 	{
					 	pBar.setForeground(Color.RED);
				 	}
				 	else
				 	{
					 	pBar.setForeground(Color.GREEN);
				 	}
				 	pBar.setValue(counter);				 	
				 	pBar.setString(counter + " Packets");//you can do this in your renderer class
				 	
				 	pBar2.setValue(rate);
				 	pBar2.setString(rate + " Packets");
				 	break;
					 
			 	}
			 	framing.repaint();
	 
		 	}
	 	}
		 
	 }
	 catch(Exception eeee)
	 {}
	 
	 }
Any help would be appreciated
So plz help i m running out of time and my teacher wont accept this after the deadline.

Thanks and Regards
Reply With Quote
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can you use the keyboard to activate a JComboBox within a JTable without using F2 lisae Java 8 09-29-2009 02:35 PM
hello problem with jtable and database data pankajkaushal NetBeans 3 06-02-2009 03:00 PM
Hashtable vs List thnts45 Java 2 02-02-2009 03:04 AM
Set focus to a specific cell in a JTable diasmvds Java 0 08-12-2008 07:13 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com