Krolyxon
Commit 1d11df0

Branches

Refs →

jcal1d11df0

GUI: progress

Author
krolxon
Date
2024-02-16 23:04 +0530
Parent
29eeb51
Commit
1d11df081f3d0213e7ffc9fd7b2846a8bb9bb5c9

+146 −15

24 files changed

  1. M GFrame.java +130 −15
  2. A History.java +16 −0
  3. M bin/GFrame$1.class
  4. A bin/GFrame$10.class
  5. A bin/GFrame$11.class
  6. A bin/GFrame$12.class
  7. A bin/GFrame$13.class
  8. A bin/GFrame$14.class
  9. A bin/GFrame$15.class
  10. A bin/GFrame$16.class
  11. A bin/GFrame$17.class
  12. A bin/GFrame$18.class
  13. A bin/GFrame$19.class
  14. M bin/GFrame$2.class
  15. A bin/GFrame$20.class
  16. A bin/GFrame$3.class
  17. A bin/GFrame$4.class
  18. A bin/GFrame$5.class
  19. A bin/GFrame$6.class
  20. A bin/GFrame$7.class
  21. A bin/GFrame$8.class
  22. A bin/GFrame$9.class
  23. M bin/GFrame.class
  24. A bin/History.class
M GFrame.java View
@@ -1,54 +1,169 @@
1+import java.util.Vector;
12 import javax.swing.*;
23 import java.awt.Color;
34 import java.awt.Dimension;
5+import java.awt.Font;
6+import java.awt.Insets;
47 import java.awt.event.*;
58
69 public class GFrame extends JFrame {
710 Parser p;
11+ JTextField tf;
12+
13+ private JButton newButton(String text, int d1, int d2, int d3, int d4) {
14+ JButton b = new JButton();
15+ // b.setBackground(Color.decode("#F78361"));
16+ b.setBackground(Color.decode("#2B2B2B"));
17+ b.setForeground(Color.decode("#e5e5e5"));
18+ b.setFont((new Font("Times New Roman", Font.PLAIN, 20)));
19+ b.setBounds(d1, d2, d3, d4);
20+ b.setText(text);
21+ return b;
22+ }
23+
24+ private void actionAdderForTextField(JButton b, String val) {
25+ b.addActionListener(new ActionListener() {
26+ public void actionPerformed(ActionEvent e) {
27+ tf.setText(tf.getText() + val);
28+ }
29+ });
30+
31+ }
832
933 GFrame(String title) {
34+ History history = new History();
1035 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1136 this.setTitle(title);
12− this.getContentPane().setBackground(Color.decode("#4E586e"));
13− JButton b = new JButton();
14− b.setBounds(130, 100, 100, 40);
15− b.setBackground(Color.decode("#F78361"));
16− b.setText("Evaluate");
37+ this.getContentPane().setBackground(Color.decode("#111111"));
38+ this.setResizable(false);
1739
18− JTextField tf = new JTextField();
19− tf.setBounds(130, 50, 220, 40);
40+ // Text Field
41+ tf = new JTextField();
42+ tf.setBackground(Color.decode("#2B2B2B"));
43+ tf.setForeground(Color.decode("#e5e5e5"));
44+ tf.setMargin(new Insets(0, 10, 0, 10));
45+ tf.setBounds(40, 50, 310, 40);
46+ tf.setFont((new Font("Times New Roman", Font.PLAIN, 20)));
2047
21− JButton bClear = new JButton();
22− bClear.setBounds(250, 100, 100, 40);
23− bClear.setBackground(Color.decode("#F78361"));
24− bClear.setText("Clear");
48+ // History Text Field
49+ JTextField tHist = new JTextField();
50+ tHist.setBounds(100, 10, 310, 40);
51+ tHist.setEditable(false);
2552
26− this.add(b);
53+ // Buttons
54+ JButton bEval = newButton("=", 250, 100, 100, 40);
55+ JButton bClear = newButton("CL", 180, 100, 60, 40);
56+ JButton bAdd = newButton("+", 250, 300, 100, 40);
57+ JButton bSub = newButton("-", 250, 250, 100, 40);
58+ JButton bMul = newButton("X", 250, 200, 100, 40);
59+ JButton bDiv = newButton("%", 250, 150, 100, 40);
60+ JButton bCut = newButton("<x", 180, 300, 60, 40);
61+ JButton bRightPar = newButton(")", 110, 100, 60, 40);
62+ JButton bLeftPar = newButton("(", 40, 100, 60, 40);
63+ JButton bDoubleZero = newButton("00", 40, 300, 60, 40);
64+ JButton bZero = newButton("0", 110, 300, 60, 40);
65+ JButton bOne = newButton("1", 40, 250, 60, 40);
66+ JButton bTwo = newButton("2", 110, 250, 60, 40);
67+ JButton bThree = newButton("3", 180, 250, 60, 40);
68+ JButton bFour = newButton("4", 40, 200, 60, 40);
69+ JButton bFive = newButton("5", 110, 200, 60, 40);
70+ JButton bSix = newButton("6", 180, 200, 60, 40);
71+ JButton bSeven = newButton("7", 40, 150, 60, 40);
72+ JButton bEight = newButton("8", 110, 150, 60, 40);
73+ JButton bNine = newButton("9", 180, 150, 60, 40);
74+
75+ // Add the buttons to the Frame
76+ this.add(bEval);
2777 this.add(bClear);
78+ this.add(bAdd);
79+ this.add(bSub);
80+ this.add(bMul);
81+ this.add(bDiv);
82+ this.add(bCut);
83+ this.add(bRightPar);
84+ this.add(bLeftPar);
85+ this.add(bDoubleZero);
86+ this.add(bZero);
87+ this.add(bOne);
88+ this.add(bTwo);
89+ this.add(bThree);
90+ this.add(bFour);
91+ this.add(bFive);
92+ this.add(bSix);
93+ this.add(bSeven);
94+ this.add(bEight);
95+ this.add(bNine);
2896 this.add(tf);
29− this.setSize(400, 500);
97+ // this.add(tHist);
98+ this.setSize(400, 400);
3099 this.setLayout(null);
31100 this.setVisible(true);
32101
33102 JLabel label = new JLabel("Enter Expression: ");
34− label.setBounds(130, 20, 150, 40);
103+ label.setFont((new Font("Times New Roman", Font.PLAIN, 20)));
104+ label.setBounds(40, 20, 150, 40);
105+ label.setForeground(Color.decode("#e5e5e5"));
35106 this.add(label);
36107
37− b.addActionListener(new ActionListener() {
108+ // ActionsListeners
109+ bEval.addActionListener(new ActionListener() {
38110 public void actionPerformed(ActionEvent e) {
39111 if (tf.getText().length() != 0) {
40112 p = new Parser(tf.getText());
41113 tf.setText(Double.toString(p.eval()));
114+
115+ // Save to history
116+ history.addHistory(tf.getText());
117+
118+ tHist.setText("");
119+ Vector<String> s = history.getHistory();
120+ for (int i = 0; i < s.size(); i++) {
121+ System.out.println(s.get(i));
122+ tHist.setText(new String(s.get(i).concat(tHist.getText())).concat("\n"));
123+ }
124+
42125 } else {
43126 tf.setText("No input");
44127 }
45128 }
46129 });
47130
131+ // Common actions that just appends the symbols to the text field
132+ actionAdderForTextField(bAdd, "+");
133+ actionAdderForTextField(bSub, "-");
134+ actionAdderForTextField(bMul, "*");
135+ actionAdderForTextField(bDiv, "/");
136+ actionAdderForTextField(bRightPar, ")");
137+ actionAdderForTextField(bLeftPar, "(");
138+ actionAdderForTextField(bDoubleZero, "00");
139+ actionAdderForTextField(bZero, "0");
140+ actionAdderForTextField(bOne, "1");
141+ actionAdderForTextField(bTwo, "2");
142+ actionAdderForTextField(bThree, "3");
143+ actionAdderForTextField(bFour, "4");
144+ actionAdderForTextField(bFive, "5");
145+ actionAdderForTextField(bSix, "6");
146+ actionAdderForTextField(bSeven, "7");
147+ actionAdderForTextField(bEight, "8");
148+ actionAdderForTextField(bNine, "9");
149+
48150 bClear.addActionListener(new ActionListener() {
49151 public void actionPerformed(ActionEvent e) {
50152 tf.setText("");
51153 }
52154 });
155+
156+ bCut.addActionListener(new ActionListener() {
157+ public void actionPerformed(ActionEvent e) {
158+ String text = tf.getText();
159+ tf.setText(text.substring(0, text.length() - 1));
160+ }
161+ });
162+
163+ // bOne.addActionListener(new ActionListener() {
164+ // public void actionPerformed(ActionEvent e) {
165+ // tf.setText(tf.getText() + "1");
166+ // }
167+ // });
53168 }
54169 }
A History.java View
@@ -0,0 +1,16 @@
1+import java.util.Vector;
2+
3+public class History {
4+ private Vector<String> hist;
5+
6+ History() {
7+ hist = new Vector<String>();
8+ }
9+
10+ public void addHistory(String h) {
11+ hist.add(h);
12+ }
13+ public Vector<String> getHistory() {
14+ return hist;
15+ }
16+}
M bin/GFrame$1.class View

[Binary file]

A bin/GFrame$10.class View

[Binary file]

A bin/GFrame$11.class View

[Binary file]

A bin/GFrame$12.class View

[Binary file]

A bin/GFrame$13.class View

[Binary file]

A bin/GFrame$14.class View

[Binary file]

A bin/GFrame$15.class View

[Binary file]

A bin/GFrame$16.class View

[Binary file]

A bin/GFrame$17.class View

[Binary file]

A bin/GFrame$18.class View

[Binary file]

A bin/GFrame$19.class View

[Binary file]

M bin/GFrame$2.class View

[Binary file]

A bin/GFrame$20.class View

[Binary file]

A bin/GFrame$3.class View

[Binary file]

A bin/GFrame$4.class View

[Binary file]

A bin/GFrame$5.class View

[Binary file]

A bin/GFrame$6.class View

[Binary file]

A bin/GFrame$7.class View

[Binary file]

A bin/GFrame$8.class View

[Binary file]

A bin/GFrame$9.class View

[Binary file]

M bin/GFrame.class View

[Binary file]

A bin/History.class View

[Binary file]