Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JApplet Hangs !

843804Apr 7 2005
my JApplet hangs when i double click on any cell of my JTable.
I m unable to discover the problem since a week.

i am using a thread which runs in infinite loop for displaying data in my JApplet.
i had added mouse listener for JTable. and the code is
t is JTable object .
pop is JPopup Object.
p is panel object.

mi = new MenuItem("Add");
			mi.addActionListener(this);
			    popup.add(mi);
			mi = new MenuItem("Delete");
			mi.addActionListener(this);
			    popup.add(mi);
			popup.addSeparator();
			mi = new MenuItem("Link to profile");
			mi.addActionListener(this);
			    popup.add(mi);
			mi = new MenuItem("Link to News");
			mi.addActionListener(this);
			    popup.add(mi);
			popup.addSeparator();
			mi = new MenuItem("Move row Up");
			mi.addActionListener(this);
			    popup.add(mi);
			mi = new MenuItem("Move row Down");
			mi.addActionListener(this);
			    popup.add(mi);
		p.add(popup);
t.addMouseListener(
  		 new MouseListener() {
   		    public void mouseClicked(MouseEvent e) {
			if(SwingUtilities.isRightMouseButton(e)) {
		         	   try {
				popup.show(e.getComponent(), e.getX(), e.getY());					
			        }catch(Exception ex){System.out.println("Error showing PopupMenu"+ex);} 
			}//if closed
    		   }
    		   public void mousePressed(MouseEvent e) {
				Point p = e.getPoint();
				copyIndex = t.rowAtPoint(p);
				t.setSelectionForeground(Color.white);

				if(SwingUtilities.isLeftMouseButton(e)) 
				{
					if(copyIndex%2==0)
						t.setSelectionBackground(new Color(color_code[0],color_code[1],color_code[2]));
					else
						t.setSelectionBackground(new Color(color_code[3],color_code[4],color_code[5]));
				}
				if(SwingUtilities.isRightMouseButton(e)) 
				{
	         				 if(t.getRowCount()==1)
					{
					if( ((MenuItem)popup.getItem(1)).getActionCommand().equals("Delete") )
							{ popup.remove(1); }
					}
					if(t.getRowCount()==20)
					{
					if( ((MenuItem)popup.getItem(0)).getActionCommand().equals("Add") )
							 popup.remove(0);
					}
					if( getParameter("WLMarketName").equals(getParameter("watchlistname")) )
			   		{
					if( ((MenuItem)popup.getItem(0)).getActionCommand().equals("Add") )
							 popup.remove(0);
					}
				}
			}
    		   public void mouseReleased(MouseEvent e) {
				Point p = e.getPoint();
				pasteIndex = t.rowAtPoint(p);
				if(SwingUtilities.isLeftMouseButton(e)) 
				{
					if(copyIndex!=pasteIndex)
					{
					//Swapping rows value manually
					String temp[]=new String[(colSize+1)+1];
					for(int i=0;i<temp.length;i++)	
						{temp=(String)t.getValueAt(pasteIndex,i);}
for(int i=0;i<temp.length;i++)
{ t.setValueAt(t.getValueAt(copyIndex,i),pasteIndex,i); }
for(int i=0;i<temp.length;i++)
{ t.setValueAt(temp[i],copyIndex,i); }
//sending temporary row arrangement to servlet to get it permanent
String rowArrangement="";
for(int i=0;i<recSize;i++)
{ rowArrangement=rowArrangement+(String)t.getValueAt(i,0)+"*"; }
try{
wheretogo=1;
AppletContext ac=getAppletContext();
URL url=getCodeBase();
ac.showDocument(new URL(url+"SaveRowArrangementServlet?Arrange="+rowArrangement));
}catch(Exception ex) {System.out.println(ex);}
}//if closed
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}
);

The applet console also hangs , which was a good source for discovering the error. can any hint me about the problem.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2005
Added on Apr 7 2005
0 comments
66 views