Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 05-15-2008, 07:03 AM
Member
 
Join Date: May 2008
Posts: 2
salmanpirzada1 is on a distinguished road
Jtable duplicates through Hashtable (JTable condition problem) my assignment plz help
My code is working fine showing ip addresses uniquely. When ever a packet comes my code just adds the information in a row of jtable and updates as the same packet comes again by increasing the jtable value by 1. But now the situation is different. I need to add the same ip again in a new row bcoz i has different operation now. I am doing it using hashtable. Plz see the code and help if possible since i m trying for several hours. Tomorrow is my final presentation day and i m stuck in here.

I am posting a short form of my code so that you people can help me easily, but if you want, i will post my whole class for ease. My code is as follows



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) {} }
Kindly plz help i m running out of time and my project will be cancelled then.

Any help would be appreciated.

Thanks n Regards
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-15-2008, 10:35 AM
Member
 
Join Date: May 2008
Posts: 1
mr.thickbrain is on a distinguished road
i blieve the reason your information gets updated in the hastable is because you hash using the ip and hashing the same ip returns the same hash value. i hope that helps.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-15-2008, 11:15 AM
Member
 
Join Date: May 2008
Posts: 2
salmanpirzada1 is on a distinguished road
No u didnt get me. 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.

Code:
public void recieve(String[] a,int nums,int no_of,String udpval) { try { operation = a[0]; 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) && ! ht.containsValue(operation)) { counter = 1;//counter=counter+1; rate = pack_siz; ht.put(ip,operation); ht1.put(coun,counter); tabModel.addRow(new Object[]{ip,operation,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(ht1.get(coun)));//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) && tabModel.getValueAt(u,1).equals(operation)) { Object o_val = tabModel.getValueAt(u,2); ++counter;//increment the counter by 1 ht.put(ip,operation); ht1.put(coun,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) {} }
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with jTable that is binded with a table in MySQL Database rajkenneth NetBeans 0 03-29-2008 04:36 PM
Sorting JTable (Vectors) Problem ramapple AWT / Swing 5 02-05-2008 09:54 AM
How to add in a new row in Jtable? Ry4n AWT / Swing 0 01-18-2008 01:26 PM
problem in redrawing JTable abhinav AWT / Swing 0 11-21-2007 10:08 PM
Problem with JTable Felissa AWT / Swing 2 07-04-2007 10:25 AM


All times are GMT +3. The time now is 12:46 AM.


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