aboutsummaryrefslogtreecommitdiff
path: root/GFrame.java
diff options
context:
space:
mode:
authorkrolxon <krolyxon@tutanota.com>2024-02-16 00:09:35 +0530
committerkrolxon <krolyxon@tutanota.com>2024-02-16 00:09:35 +0530
commit29eeb5191923e2f1e590b9ad28683f7458e736b5 (patch)
treeeb602c91e380e02f00a1cb63124d9109fc99638a /GFrame.java
parentc62432ebdacb54f58b0908f11879235d15460cf0 (diff)
change how your interact with Parser
Diffstat (limited to 'GFrame.java')
-rw-r--r--GFrame.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/GFrame.java b/GFrame.java
new file mode 100644
index 0000000..b8ef7ed
--- /dev/null
+++ b/GFrame.java
@@ -0,0 +1,54 @@
+import javax.swing.*;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.*;
+
+public class GFrame extends JFrame {
+ Parser p;
+
+ GFrame(String title) {
+ 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");
+
+ JTextField tf = new JTextField();
+ tf.setBounds(130, 50, 220, 40);
+
+ JButton bClear = new JButton();
+ bClear.setBounds(250, 100, 100, 40);
+ bClear.setBackground(Color.decode("#F78361"));
+ bClear.setText("Clear");
+
+ this.add(b);
+ this.add(bClear);
+ this.add(tf);
+ this.setSize(400, 500);
+ this.setLayout(null);
+ this.setVisible(true);
+
+ JLabel label = new JLabel("Enter Expression: ");
+ label.setBounds(130, 20, 150, 40);
+ this.add(label);
+
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (tf.getText().length() != 0) {
+ p = new Parser(tf.getText());
+ tf.setText(Double.toString(p.eval()));
+ } else {
+ tf.setText("No input");
+ }
+ }
+ });
+
+ bClear.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ tf.setText("");
+ }
+ });
+ }
+}