1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 15:30:09 -08:00

Tidy Window class with more explicit variable names and private vars.

This commit is contained in:
Danila Fedorin 2017-07-25 21:13:18 -07:00
parent b93346ec37
commit 7e7525cf37

View File

@ -4,60 +4,77 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
public class Window extends JFrame { public class Window extends JFrame {
private String history; private String history;
private String lastOutput; private String lastOutput;
public Window(){
private JPanel outputPanel;
private JTextArea lastOutputArea;
private JTextArea historyArea;
private JScrollPane historyAreaScroll;
private JPanel inputPanel;
private JTextField inputField;
private JButton inputEnterButton;
private JPanel sidePanel;
private JPanel numberSystemPanel;
private JComboBox<String> numberSystemList;
private JButton functionSelectButton;
private JPanel functionSelectPanel;
private JComboBox<String> functionList;
public Window() {
super(); super();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) { history = "";
e.printStackTrace(); lastOutput = "";
} catch (InstantiationException e) {
e.printStackTrace(); setSize(640, 480);
} catch (IllegalAccessException e) {
e.printStackTrace(); inputField = new JTextField();
} catch (UnsupportedLookAndFeelException e) { inputEnterButton = new JButton("Calculate");
e.printStackTrace();
} inputPanel = new JPanel();
inputPanel.setLayout(new BorderLayout());
//JFrame super= new JFrame(); inputPanel.add(inputField);
//ImageIcon check = new ImageIcon(".\\Window Images\\Untitled.png"); inputPanel.add(inputEnterButton, BorderLayout.LINE_END);
String check = "Enter";
JButton checkButton = new JButton(check); historyArea = new JTextArea(history);
JTextField inputBox = new JTextField(); historyAreaScroll = new JScrollPane(historyArea);
history=""; lastOutputArea = new JTextArea(lastOutput);
JTextArea historyBox = new JTextArea(history); lastOutputArea.setEditable(false);
JScrollPane scrollHistoryBox = new JScrollPane(historyBox); lastOutputArea.setText(":)");
JTextArea outputBox = new JTextArea(lastOutput);
JPanel output=new JPanel(); outputPanel = new JPanel();
output.setLayout(new BorderLayout()); outputPanel.setLayout(new BorderLayout());
output.add(scrollHistoryBox); outputPanel.add(historyAreaScroll);
output.add(outputBox, BorderLayout.PAGE_END); outputPanel.add(lastOutputArea, BorderLayout.PAGE_END);
JPanel input = new JPanel();
input.setLayout(new BorderLayout()); numberSystemList = new JComboBox<>();
input.add(inputBox);
input.add(checkButton, BorderLayout.LINE_END); numberSystemPanel = new JPanel();
super.add(output); numberSystemPanel.setLayout(new BorderLayout());
JPanel custom = new JPanel(); numberSystemPanel.add(new JLabel("Number Type:"));
JPanel numCustom = new JPanel(); numberSystemPanel.add(numberSystemList, BorderLayout.PAGE_END);
JPanel funCustom = new JPanel();
custom.setLayout(new BorderLayout()); functionList = new JComboBox<>();
numCustom.setLayout(new BorderLayout()); functionSelectButton = new JButton("Select");
funCustom.setLayout(new BorderLayout());
JTextArea numLabel = new JTextArea("Number Type:"); functionSelectPanel = new JPanel();
JTextArea funLabel = new JTextArea("Functions:"); functionSelectPanel.setLayout(new BorderLayout());
JComboBox<String> numList = new JComboBox(); functionSelectPanel.add(new JLabel("Functions:"));
JComboBox<String> funList = new JComboBox(); functionSelectPanel.add(functionList, BorderLayout.LINE_END);
JButton funCheckButton = new JButton(check); functionSelectPanel.add(functionSelectButton, BorderLayout.LINE_END);
numCustom.add(numLabel);
numCustom.add(numList, BorderLayout.PAGE_END); sidePanel = new JPanel();
funCustom.add(funList); sidePanel.setLayout(new BorderLayout());
funCustom.add(funCheckButton, BorderLayout.LINE_END); sidePanel.add(numberSystemPanel);
funCustom.add(funLabel, BorderLayout.PAGE_START); sidePanel.add(functionSelectPanel, BorderLayout.PAGE_END);
custom.add(numCustom);
custom.add(funCustom, BorderLayout.PAGE_END); add(outputPanel, BorderLayout.CENTER);
super.add(custom, BorderLayout.LINE_END); add(sidePanel, BorderLayout.EAST);
super.add(input, BorderLayout.PAGE_END); add(inputPanel, BorderLayout.SOUTH);
super.setVisible(true);
} }
} }