Stack stack = new Stack();button.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){stack.push(field1.getText());field2.setText(stack.pop());}});