title: Variables set in function are constantly changed
body: <p>I want to implement operation undo in game solitaire. I have  I create function save which will copy actual state of elements and function load which will overrides actual elements with these copies. But when I call function save before some operation with card the function save values but when source of these values change these variables change too. </p>
  
  <p>These variables are set in this class before constructor:</p>
  
  <pre><code>public class Game extends javax.swing.JPanel 
  </code></pre>
  
  <p>like this</p>
  
  <pre><code>ArrayList&lt;CardStack&gt; undo_card_stack1 = new ArrayList&lt;&gt;(); 
  </code></pre>
  
  <p>Function save_undo simply copy actual state of values to these undo values like this:</p>
  
  <pre><code>private void save_undo()  
  {
     undo_card_stack1.add(working_pack1_stack);
     undo_card_stack2.add(working_pack2_stack);
  ....
  </code></pre>
  
  <p>Function is calls before every action with card - card is JLabel.
  What is not clear to me is why when debugging this part of code are values correctly set after save_undo() calls, but after operation with pop and push few lines after are values rewrites.</p>
  
  <pre><code>private void start_deckMouseClicked(java.awt.event.MouseEvent evt) {                                        
  
      save_undo();
      discardPile_card = null;
      if (!deck.isEmpty())
      {
  
          discardPile.deck.push(deck.pop());
          ...
  </code></pre>
  
  <p>Function load do exactly opposite of save and is calls when button clicked:</p>
  
  <pre><code>private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      load_undo();
  } 
  </code></pre>