if (parent.getLayout() != this) throw new IllegalArgumentException("parent's layout is not this CardLayout");
  private void gotoComponent (Container parent, int what)  {    synchronized (parent.getTreeLock ())      {	int num = parent.ncomponents;	// This is more efficient than calling getComponents().	Component[] comps = parent.component;	if (num == 1)	  {	    comps[0].setVisible(true);	    return;	  }	int choice = -1;	if (what == FIRST)	  choice = 0;	else if (what == LAST)	  choice = num - 1;	for (int i = 0; i < num; ++i)	  {	    if (comps[i].isVisible ())	      {		if (what == NEXT)		  {		    choice = i + 1;		    if (choice == num)		      choice = 0;		  }		else if (what == PREV)		  {		    choice = i - 1;		    if (choice < 0)		      choice = num - 1;		  }		else if (choice == i)		  {		    // Do nothing if we're already looking at the right		    // component.		    return;		  }		comps[i].setVisible (false); 		if (choice >= 0)		  break;	      }	  }	if (choice >= 0 && choice < num)	  comps[choice].setVisible (true);      }  }