2017-07-25 14:52:57 -07:00
|
|
|
package org.nwapw.abacus.window;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The main UI window for the calculator.
|
|
|
|
*/
|
2017-07-25 14:52:57 -07:00
|
|
|
public class Window extends JFrame {
|
2017-07-25 21:13:18 -07:00
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* A collection of outputs from the calculator.
|
|
|
|
*/
|
2017-07-25 14:52:57 -07:00
|
|
|
private String history;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The last output by the calculator.
|
|
|
|
*/
|
2017-07-25 14:52:57 -07:00
|
|
|
private String lastOutput;
|
2017-07-25 21:13:18 -07:00
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The panel where the output occurs.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JPanel outputPanel;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The text area reserved for the last output.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JTextArea lastOutputArea;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The text area used for all history output.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JTextArea historyArea;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The scroll pane for the history area.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JScrollPane historyAreaScroll;
|
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The panel where the input occurs.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JPanel inputPanel;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The input text field.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JTextField inputField;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The "submit" button.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JButton inputEnterButton;
|
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The side panel for separate configuration.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JPanel sidePanel;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* Panel for elements relating to number
|
|
|
|
* system selection.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JPanel numberSystemPanel;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The possible list of number systems.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JComboBox<String> numberSystemList;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The panel for elements relating to
|
|
|
|
* function selection.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JPanel functionSelectPanel;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The list of functions available to the user.
|
|
|
|
*/
|
2017-07-25 21:13:18 -07:00
|
|
|
private JComboBox<String> functionList;
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The button used to select a function.
|
|
|
|
*/
|
|
|
|
private JButton functionSelectButton;
|
2017-07-25 21:13:18 -07:00
|
|
|
|
|
|
|
public Window() {
|
2017-07-25 14:52:57 -07:00
|
|
|
super();
|
2017-07-25 21:13:18 -07:00
|
|
|
|
|
|
|
|
|
|
|
history = "";
|
|
|
|
lastOutput = "";
|
|
|
|
|
|
|
|
setSize(640, 480);
|
|
|
|
|
|
|
|
inputField = new JTextField();
|
|
|
|
inputEnterButton = new JButton("Calculate");
|
|
|
|
|
|
|
|
inputPanel = new JPanel();
|
|
|
|
inputPanel.setLayout(new BorderLayout());
|
2017-07-25 22:08:12 -07:00
|
|
|
inputPanel.add(inputField, BorderLayout.CENTER);
|
|
|
|
inputPanel.add(inputEnterButton, BorderLayout.EAST);
|
2017-07-25 21:13:18 -07:00
|
|
|
|
|
|
|
historyArea = new JTextArea(history);
|
|
|
|
historyAreaScroll = new JScrollPane(historyArea);
|
|
|
|
lastOutputArea = new JTextArea(lastOutput);
|
|
|
|
lastOutputArea.setEditable(false);
|
|
|
|
lastOutputArea.setText(":)");
|
|
|
|
|
|
|
|
outputPanel = new JPanel();
|
|
|
|
outputPanel.setLayout(new BorderLayout());
|
2017-07-25 22:08:12 -07:00
|
|
|
outputPanel.add(historyAreaScroll, BorderLayout.CENTER);
|
|
|
|
outputPanel.add(lastOutputArea, BorderLayout.SOUTH);
|
2017-07-25 21:13:18 -07:00
|
|
|
|
|
|
|
numberSystemList = new JComboBox<>();
|
|
|
|
|
|
|
|
numberSystemPanel = new JPanel();
|
|
|
|
numberSystemPanel.setLayout(new BorderLayout());
|
2017-07-25 22:08:12 -07:00
|
|
|
numberSystemPanel.add(new JLabel("Number Type:"), BorderLayout.NORTH);
|
|
|
|
numberSystemPanel.add(numberSystemList, BorderLayout.CENTER);
|
2017-07-25 21:13:18 -07:00
|
|
|
|
|
|
|
functionList = new JComboBox<>();
|
|
|
|
functionSelectButton = new JButton("Select");
|
|
|
|
|
|
|
|
functionSelectPanel = new JPanel();
|
|
|
|
functionSelectPanel.setLayout(new BorderLayout());
|
2017-07-25 22:08:12 -07:00
|
|
|
functionSelectPanel.add(new JLabel("Functions:"), BorderLayout.NORTH);
|
|
|
|
functionSelectPanel.add(functionList, BorderLayout.CENTER);
|
|
|
|
functionSelectPanel.add(functionSelectButton, BorderLayout.SOUTH);
|
2017-07-25 21:13:18 -07:00
|
|
|
|
|
|
|
sidePanel = new JPanel();
|
|
|
|
sidePanel.setLayout(new BorderLayout());
|
2017-07-25 22:08:12 -07:00
|
|
|
sidePanel.add(numberSystemPanel, BorderLayout.NORTH);
|
|
|
|
sidePanel.add(functionSelectPanel, BorderLayout.SOUTH);
|
2017-07-25 21:13:18 -07:00
|
|
|
|
|
|
|
add(outputPanel, BorderLayout.CENTER);
|
|
|
|
add(sidePanel, BorderLayout.EAST);
|
|
|
|
add(inputPanel, BorderLayout.SOUTH);
|
2017-07-25 14:52:57 -07:00
|
|
|
}
|
|
|
|
}
|