jcal1d11df0
GUI: progress
+146 −15
24 files changed
- M GFrame.java +130 −15
- A History.java +16 −0
- M bin/GFrame$1.class
- A bin/GFrame$10.class
- A bin/GFrame$11.class
- A bin/GFrame$12.class
- A bin/GFrame$13.class
- A bin/GFrame$14.class
- A bin/GFrame$15.class
- A bin/GFrame$16.class
- A bin/GFrame$17.class
- A bin/GFrame$18.class
- A bin/GFrame$19.class
- M bin/GFrame$2.class
- A bin/GFrame$20.class
- A bin/GFrame$3.class
- A bin/GFrame$4.class
- A bin/GFrame$5.class
- A bin/GFrame$6.class
- A bin/GFrame$7.class
- A bin/GFrame$8.class
- A bin/GFrame$9.class
- M bin/GFrame.class
- A bin/History.class
| @@ -1,54 +1,169 @@ | |||
| 1 | + | import java.util.Vector; | |
| 1 | 2 | import javax.swing.*; | |
| 2 | 3 | import java.awt.Color; | |
| 3 | 4 | import java.awt.Dimension; | |
| 5 | + | import java.awt.Font; | |
| 6 | + | import java.awt.Insets; | |
| 4 | 7 | import java.awt.event.*; | |
| 5 | 8 | ||
| 6 | 9 | public class GFrame extends JFrame { | |
| 7 | 10 | 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 | + | } | |
| 8 | 32 | ||
| 9 | 33 | GFrame(String title) { | |
| 34 | + | History history = new History(); | |
| 10 | 35 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
| 11 | 36 | 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); | |
| 17 | 39 | ||
| 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))); | |
| 20 | 47 | ||
| 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); | |
| 25 | 52 | ||
| 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); | |
| 27 | 77 | 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); | |
| 28 | 96 | this.add(tf); | |
| 29 | − | this.setSize(400, 500); | |
| 97 | + | // this.add(tHist); | |
| 98 | + | this.setSize(400, 400); | |
| 30 | 99 | this.setLayout(null); | |
| 31 | 100 | this.setVisible(true); | |
| 32 | 101 | ||
| 33 | 102 | 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")); | |
| 35 | 106 | this.add(label); | |
| 36 | 107 | ||
| 37 | − | b.addActionListener(new ActionListener() { | |
| 108 | + | // ActionsListeners | |
| 109 | + | bEval.addActionListener(new ActionListener() { | |
| 38 | 110 | public void actionPerformed(ActionEvent e) { | |
| 39 | 111 | if (tf.getText().length() != 0) { | |
| 40 | 112 | p = new Parser(tf.getText()); | |
| 41 | 113 | 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 | + | ||
| 42 | 125 | } else { | |
| 43 | 126 | tf.setText("No input"); | |
| 44 | 127 | } | |
| 45 | 128 | } | |
| 46 | 129 | }); | |
| 47 | 130 | ||
| 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 | + | ||
| 48 | 150 | bClear.addActionListener(new ActionListener() { | |
| 49 | 151 | public void actionPerformed(ActionEvent e) { | |
| 50 | 152 | tf.setText(""); | |
| 51 | 153 | } | |
| 52 | 154 | }); | |
| 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 | + | // }); | |
| 53 | 168 | } | |
| 54 | 169 | } | |
| @@ -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 | + | } | |
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]
[Binary file]