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

    Default 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



    Java 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

  2. #2
    mr.thickbrain is offline Member
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Default

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default

    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.

    Java 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)
    	 {}
    	 
    	 }

Similar Threads

  1. Sorting JTable (Vectors) Problem
    By ramapple in forum AWT / Swing
    Replies: 6
    Last Post: 07-06-2009, 11:15 PM
  2. Replies: 0
    Last Post: 03-29-2008, 03:36 PM
  3. How to add in a new row in Jtable?
    By Ry4n in forum AWT / Swing
    Replies: 0
    Last Post: 01-18-2008, 12:26 PM
  4. problem in redrawing JTable
    By abhinav in forum AWT / Swing
    Replies: 0
    Last Post: 11-21-2007, 09:08 PM
  5. Problem with JTable
    By Felissa in forum AWT / Swing
    Replies: 2
    Last Post: 07-04-2007, 09:25 AM

Posting Permissions

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