import javax.swing.*;import java.awt.*;import java.awt.event.*;public class TakeAwayGUI extends JFrame implements ActionListener {    private JTextArea display;    private JTextField inField;    private JButton goButton;    private TakeAwayGame game;	        public TakeAwayGUI(String title) {        game = new TakeAwayGame();      	buildGUI();        setTitle(title);        pack();        show();    }            private void buildGUI() {        Container contentPane = getContentPane();    	contentPane.setLayout(new BorderLayout());        display = new JTextArea(20,30);        display.setText("Let's play Take Away. There are " + game.sticksLeft() + " sticks.\n" +                        "You can pick up 1,2, or 3 at a time.\n" + "You go first.\n");        inField = new JTextField(10);        inField.addActionListener(this);        goButton = new JButton("Take Away!");        goButton.addActionListener(this);        JPanel inputPanel = new JPanel();        inputPanel.add(new JLabel("How many sticks do you take: "));        inputPanel.add(inField);        inputPanel.add(goButton);        contentPane.add("Center", display);        contentPane.add("South", inputPanel);    }        private void userMove() {        int userTakes = Integer.parseInt(inField.getText());        if (game.takeAway(userTakes)) {            display.append("You take " + userTakes + ".\n");	    } else {            display.append("Sorry, you can't take " + userTakes + ". Try again\n");	    }    }    private void computerMove() {        int maxTakeAway = Math.min(game.sticksLeft(), TakeAwayGame.MAX_TAKE_AWAY);        int computerTakes = 1 + (int)(Math.random() * maxTakeAway);	    game.takeAway(computerTakes);        display.append("I take " + computerTakes + ". ");    }    public void actionPerformed(ActionEvent e) {	    int sticksLeft = 0;        if (e.getSource() == goButton || e.getSource() == inField) {            userMove();            if (game.gameOver() == false)                if (game.getPlayer() == game.COMPUTER)                     computerMove();            sticksLeft = game.sticksLeft();            display.append("There are " + sticksLeft + " sticks left.\n");            if (game.gameOver()) {                goButton.setEnabled(false);  // End the game                inField.setEnabled(false);                if (game.getWinner() == game.USER)                    display.append("Game over. You win. Nice game.\n");                else                    display.append("Game over. I win. Nice game.\n");            }        }    } //actionPerformed()}