예제 #1
0
  /** Make the frame for the user interface. */
  private void makeFrame() {
    frame = new JFrame(calc.getTitle());

    JPanel contentPane = (JPanel) frame.getContentPane();
    contentPane.setLayout(new BorderLayout(8, 8));
    contentPane.setBorder(new EmptyBorder(20, 20, 20, 20));

    display = new JTextField();
    contentPane.add(display, BorderLayout.NORTH);

    JPanel buttonPanel = new JPanel(new GridLayout(5, 4));
    addButton(buttonPanel, "7");
    addButton(buttonPanel, "8");
    addButton(buttonPanel, "9");
    addButton(buttonPanel, "Cl");
    // had to change this, so it works in hexadecimal mode

    addButton(buttonPanel, "4");
    addButton(buttonPanel, "5");
    addButton(buttonPanel, "6");
    addButton(buttonPanel, "?");

    addButton(buttonPanel, "1");
    addButton(buttonPanel, "2");
    addButton(buttonPanel, "3");

    addButton(buttonPanel, "0");
    addButton(buttonPanel, "+");
    addButton(buttonPanel, "-");
    // Exercise 1 division
    addButton(buttonPanel, "/");
    // Exercise 1 multi
    addButton(buttonPanel, "*");

    addButton(buttonPanel, "=");

    contentPane.add(buttonPanel, BorderLayout.CENTER);

    status = new JLabel(calc.getAuthor());
    contentPane.add(status, BorderLayout.SOUTH);

    // hexa stuff
    JPanel hexContainer = new JPanel(new GridLayout(2, 1));
    JCheckBox hexBox = new JCheckBox("Hexadecimal mode");
    hexBox.addActionListener(this);

    hexContainer.add(hexBox);

    hexPanel = new JPanel(new GridLayout(2, 3));
    addButton(hexPanel, "A");
    addButton(hexPanel, "B");
    addButton(hexPanel, "C");

    addButton(hexPanel, "D");
    addButton(hexPanel, "E");
    addButton(hexPanel, "F");

    hexContainer.add(hexPanel);

    hexPanel.setVisible(false); // hide it because we start in decimal mode

    contentPane.add(hexContainer, BorderLayout.EAST);

    frame.pack();
  }
예제 #2
0
  /**
   * Toggle the info display in the calculator's status area between the author and version
   * information.
   */
  private void showInfo() {
    if (showingAuthor) status.setText(calc.getVersion());
    else status.setText(calc.getAuthor());

    showingAuthor = !showingAuthor;
  }