예제 #1
0
  public void prepareGUI() {
    mainFrame = new JFrame("Game of life");
    mainFrame.setSize(750, 670);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    grid = new GridPanel(board.getNumOfRows(), board.getNumOfColumns());
    grid.setPreferredSize(new Dimension(600, 600));
    grid.setBoard(this.board.getCurrentRound());
    grid.addMouseListener(this);

    scrollPane = new JScrollPane(grid);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    buttonStart = new JButton("Start");
    buttonStop = new JButton("Stop");
    buttonNextRound = new JButton("Next round");
    buttonClearBoard = new JButton("Clear board");

    buttonStart.setMaximumSize(
        new Dimension(Integer.MAX_VALUE, buttonStart.getMinimumSize().height));
    buttonStop.setMaximumSize(new Dimension(Integer.MAX_VALUE, buttonStop.getMinimumSize().height));
    buttonNextRound.setMaximumSize(
        new Dimension(Integer.MAX_VALUE, buttonNextRound.getMinimumSize().height));
    buttonClearBoard.setMaximumSize(
        new Dimension(Integer.MAX_VALUE, buttonClearBoard.getMinimumSize().height));

    buttonStart.addActionListener(this);
    buttonStop.addActionListener(this);
    buttonNextRound.addActionListener(this);
    buttonClearBoard.addActionListener(this);

    generationsLabel = new JLabel("Generation " + numOfGenerations);

    drawingCheckBox = new JCheckBox("Drawing");

    buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.PAGE_AXIS));
    buttonsPanel.add(buttonStart);
    buttonsPanel.add(Box.createVerticalStrut(2));
    buttonsPanel.add(buttonStop);
    buttonsPanel.add(Box.createVerticalStrut(2));
    buttonsPanel.add(buttonNextRound);
    buttonsPanel.add(Box.createVerticalStrut(2));
    buttonsPanel.add(buttonClearBoard);
    buttonsPanel.add(Box.createVerticalStrut(2));
    buttonsPanel.add(generationsLabel);
    buttonsPanel.add(Box.createVerticalStrut(2));
    buttonsPanel.add(drawingCheckBox);

    mainFrame.add(scrollPane, BorderLayout.CENTER);
    mainFrame.add(buttonsPanel, BorderLayout.EAST);
  }