Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.*;
- import java.awt.*;
- import java.util.*;
- public class Interp_1a extends JFrame
- {
- private JPanel panel;
- private JLabel msgLabel;
- private JTextArea inputTextArea;
- private JTextArea outputTextArea;
- private JButton compileButton;
- public Interp_1a()
- {
- setTitle("Interpreter w getToken()");
- setSize(300, 300);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- buildPanel();
- add(panel);
- setVisible(true);
- }
- private void buildPanel()
- {
- msgLabel = new JLabel ("");
- inputTextArea = new JTextArea(10,10);
- inputTextArea.setBackground(Color.yellow);
- inputTextArea.setForeground(Color.black);
- outputTextArea = new JTextArea(10,10);
- outputTextArea.setBackground(Color.green);
- outputTextArea.setForeground(Color.black);
- compileButton = new JButton("Compile");
- compileButton.addActionListener(new CompileListener());
- panel = new JPanel();
- panel.add(msgLabel);
- panel.add(inputTextArea);
- panel.add(outputTextArea);
- panel.add(compileButton);
- }
- public static void main(String[] args)
- {
- Interp_1a InterpObj = new Interp_1a();
- }
- private class CompileListener implements ActionListener
- {
- public void actionPerformed (ActionEvent e)
- {
- String exp;
- Interpreter InterpObj = new Interpreter();
- exp = inputTextArea.getText() + " "; // get expression from input area
- InterpObj.p = exp.toCharArray(); // convert input text to be read by interpreter
- InterpObj.counter = 0;
- double num = InterpObj.AddSub(); // doing the math
- String str = Double.toString(num); // change result into string
- outputTextArea.setText(" " + str + "\n ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement