import java.util.Vector; import javax.swing.*; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Insets; import java.awt.event.*; public class GFrame extends JFrame { Parser p; JTextField tf; private JButton newButton(String text, int d1, int d2, int d3, int d4) { JButton b = new JButton(); // b.setBackground(Color.decode("#F78361")); b.setBackground(Color.decode("#2B2B2B")); b.setForeground(Color.decode("#e5e5e5")); b.setFont((new Font("Times New Roman", Font.PLAIN, 20))); b.setBounds(d1, d2, d3, d4); b.setText(text); return b; } private void actionAdderForTextField(JButton b, String val) { b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tf.setText(tf.getText() + val); } }); } GFrame(String title) { History history = new History(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle(title); this.getContentPane().setBackground(Color.decode("#111111")); this.setResizable(false); // Text Field tf = new JTextField(); tf.setBackground(Color.decode("#2B2B2B")); tf.setForeground(Color.decode("#e5e5e5")); tf.setMargin(new Insets(0, 10, 0, 10)); tf.setBounds(40, 50, 310, 40); tf.setFont((new Font("Times New Roman", Font.PLAIN, 20))); // History Text Field JTextField tHist = new JTextField(); tHist.setBounds(100, 10, 310, 40); tHist.setEditable(false); // Buttons JButton bEval = newButton("=", 250, 100, 100, 40); JButton bClear = newButton("CL", 180, 100, 60, 40); JButton bAdd = newButton("+", 250, 300, 100, 40); JButton bSub = newButton("-", 250, 250, 100, 40); JButton bMul = newButton("X", 250, 200, 100, 40); JButton bDiv = newButton("%", 250, 150, 100, 40); JButton bCut = newButton(" s = history.getHistory(); for (int i = 0; i < s.size(); i++) { System.out.println(s.get(i)); tHist.setText(new String(s.get(i).concat(tHist.getText())).concat("\n")); } } else { tf.setText("No input"); } } }); // Common actions that just appends the symbols to the text field actionAdderForTextField(bAdd, "+"); actionAdderForTextField(bSub, "-"); actionAdderForTextField(bMul, "*"); actionAdderForTextField(bDiv, "/"); actionAdderForTextField(bRightPar, ")"); actionAdderForTextField(bLeftPar, "("); actionAdderForTextField(bDoubleZero, "00"); actionAdderForTextField(bZero, "0"); actionAdderForTextField(bOne, "1"); actionAdderForTextField(bTwo, "2"); actionAdderForTextField(bThree, "3"); actionAdderForTextField(bFour, "4"); actionAdderForTextField(bFive, "5"); actionAdderForTextField(bSix, "6"); actionAdderForTextField(bSeven, "7"); actionAdderForTextField(bEight, "8"); actionAdderForTextField(bNine, "9"); bClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tf.setText(""); } }); bCut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = tf.getText(); tf.setText(text.substring(0, text.length() - 1)); } }); // bOne.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // tf.setText(tf.getText() + "1"); // } // }); } }