View Single Post
  #1 (permalink)  
Old 05-15-2008, 08:03 AM
salmanpirzada1 salmanpirzada1 is offline
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
Reply With Quote
Sponsored Links