diff --git a/GFrame.java b/GFrame.java index b8ef7ed..885875e 100644 --- a/GFrame.java +++ b/GFrame.java @@ -1,54 +1,169 @@ +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("#4E586e")); - JButton b = new JButton(); - b.setBounds(130, 100, 100, 40); - b.setBackground(Color.decode("#F78361")); - b.setText("Evaluate"); + this.getContentPane().setBackground(Color.decode("#111111")); + this.setResizable(false); - JTextField tf = new JTextField(); - tf.setBounds(130, 50, 220, 40); + // 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))); - JButton bClear = new JButton(); - bClear.setBounds(250, 100, 100, 40); - bClear.setBackground(Color.decode("#F78361")); - bClear.setText("Clear"); + // History Text Field + JTextField tHist = new JTextField(); + tHist.setBounds(100, 10, 310, 40); + tHist.setEditable(false); - this.add(b); + // 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"); + // } + // }); } } diff --git a/History.java b/History.java new file mode 100644 index 0000000..32b8598 --- /dev/null +++ b/History.java @@ -0,0 +1,16 @@ +import java.util.Vector; + +public class History { + private Vector hist; + + History() { + hist = new Vector(); + } + + public void addHistory(String h) { + hist.add(h); + } + public Vector getHistory() { + return hist; + } +} diff --git a/bin/GFrame$1.class b/bin/GFrame$1.class index dcdfd79..57357f9 100644 Binary files a/bin/GFrame$1.class and b/bin/GFrame$1.class differ diff --git a/bin/GFrame$10.class b/bin/GFrame$10.class new file mode 100644 index 0000000..a4d46a3 Binary files /dev/null and b/bin/GFrame$10.class differ diff --git a/bin/GFrame$11.class b/bin/GFrame$11.class new file mode 100644 index 0000000..933c5b8 Binary files /dev/null and b/bin/GFrame$11.class differ diff --git a/bin/GFrame$12.class b/bin/GFrame$12.class new file mode 100644 index 0000000..6e008aa Binary files /dev/null and b/bin/GFrame$12.class differ diff --git a/bin/GFrame$13.class b/bin/GFrame$13.class new file mode 100644 index 0000000..b658e1f Binary files /dev/null and b/bin/GFrame$13.class differ diff --git a/bin/GFrame$14.class b/bin/GFrame$14.class new file mode 100644 index 0000000..80627d4 Binary files /dev/null and b/bin/GFrame$14.class differ diff --git a/bin/GFrame$15.class b/bin/GFrame$15.class new file mode 100644 index 0000000..1d741cb Binary files /dev/null and b/bin/GFrame$15.class differ diff --git a/bin/GFrame$16.class b/bin/GFrame$16.class new file mode 100644 index 0000000..f0d14b6 Binary files /dev/null and b/bin/GFrame$16.class differ diff --git a/bin/GFrame$17.class b/bin/GFrame$17.class new file mode 100644 index 0000000..4dd73cc Binary files /dev/null and b/bin/GFrame$17.class differ diff --git a/bin/GFrame$18.class b/bin/GFrame$18.class new file mode 100644 index 0000000..8b7cbc0 Binary files /dev/null and b/bin/GFrame$18.class differ diff --git a/bin/GFrame$19.class b/bin/GFrame$19.class new file mode 100644 index 0000000..c65cbea Binary files /dev/null and b/bin/GFrame$19.class differ diff --git a/bin/GFrame$2.class b/bin/GFrame$2.class index b3d4931..409c2bd 100644 Binary files a/bin/GFrame$2.class and b/bin/GFrame$2.class differ diff --git a/bin/GFrame$20.class b/bin/GFrame$20.class new file mode 100644 index 0000000..e644dac Binary files /dev/null and b/bin/GFrame$20.class differ diff --git a/bin/GFrame$3.class b/bin/GFrame$3.class new file mode 100644 index 0000000..2594add Binary files /dev/null and b/bin/GFrame$3.class differ diff --git a/bin/GFrame$4.class b/bin/GFrame$4.class new file mode 100644 index 0000000..13c9004 Binary files /dev/null and b/bin/GFrame$4.class differ diff --git a/bin/GFrame$5.class b/bin/GFrame$5.class new file mode 100644 index 0000000..a064aa2 Binary files /dev/null and b/bin/GFrame$5.class differ diff --git a/bin/GFrame$6.class b/bin/GFrame$6.class new file mode 100644 index 0000000..d52636a Binary files /dev/null and b/bin/GFrame$6.class differ diff --git a/bin/GFrame$7.class b/bin/GFrame$7.class new file mode 100644 index 0000000..4dbe1f8 Binary files /dev/null and b/bin/GFrame$7.class differ diff --git a/bin/GFrame$8.class b/bin/GFrame$8.class new file mode 100644 index 0000000..5b37273 Binary files /dev/null and b/bin/GFrame$8.class differ diff --git a/bin/GFrame$9.class b/bin/GFrame$9.class new file mode 100644 index 0000000..9373f2a Binary files /dev/null and b/bin/GFrame$9.class differ diff --git a/bin/GFrame.class b/bin/GFrame.class index 603c2f8..ce05e22 100644 Binary files a/bin/GFrame.class and b/bin/GFrame.class differ diff --git a/bin/History.class b/bin/History.class new file mode 100644 index 0000000..253fb58 Binary files /dev/null and b/bin/History.class differ