hbk619 228 Master Poster

I'm writing Solitaire in java and have each column of cards set up as a 2d arraylist of JLabels, one label hads the icon and is painted to a jpanel. The other contains the url for the image as the text of the label.

Below is part of the code used to move cards around by taking in the array of the first and second card clicked, removing the last card of the first array from the Jpanel and repainting it on the end of the second array clicked. The remove bit always takes the last but one card from the array. So the actual Jlabel (face up card) clicked remains.

Any idea why it's not removing the last card?

public void moveCard(ArrayList<ArrayList<JLabel>> columnNameFrom, ArrayList<ArrayList<JLabel>> columnNameTo, int to) throws IOException
   {
             //gidbag values
	   c.gridx = 0;
	   c.gridy = 0;
	   c.gridheight = 3;
	   c.gridwidth = 1;
            //get pos of first card clicked
	   int lastCard = columnNameFrom.size()-1;
            //get icon and url of first card clicked
	   Icon imgIcon = columnNameFrom.get(lastCard).get(0).getIcon();
	   String imgURL = columnNameFrom.get(lastCard).get(1).getText();
            //remove first card clicked from display - this bit is removing the last but one card yet columnNameFrom.get(lastCard).get(0).getName(); shows it is the right card
	   pnlImages.remove(columnNameFrom.get(lastCard).get(0));
            //update gui
	   pnlImages.revalidate();
	   pnlImages.repaint();
	   //remove that card from array
	   columnNameFrom.remove(lastCard);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.