Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. import java.awt.*;
  4. import java.util.*;
  5.  
  6. public class Interp_1a extends JFrame
  7. {
  8. private JPanel panel;
  9. private JLabel msgLabel;
  10. private JTextArea inputTextArea;
  11. private JTextArea outputTextArea;
  12. private JButton compileButton;
  13.  
  14. public Interp_1a()
  15. {
  16. setTitle("Interpreter w getToken()");
  17. setSize(300, 300);
  18. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  19.  
  20. buildPanel();
  21. add(panel);
  22. setVisible(true);
  23. }
  24.  
  25. private void buildPanel()
  26. {
  27. msgLabel = new JLabel ("");
  28.  
  29. inputTextArea = new JTextArea(10,10);
  30. inputTextArea.setBackground(Color.yellow);
  31. inputTextArea.setForeground(Color.black);
  32.  
  33. outputTextArea = new JTextArea(10,10);
  34. outputTextArea.setBackground(Color.green);
  35. outputTextArea.setForeground(Color.black);
  36.  
  37. compileButton = new JButton("Compile");
  38.  
  39. compileButton.addActionListener(new CompileListener());
  40.  
  41. panel = new JPanel();
  42.  
  43. panel.add(msgLabel);
  44. panel.add(inputTextArea);
  45. panel.add(outputTextArea);
  46. panel.add(compileButton);
  47. }
  48.  
  49. public static void main(String[] args)
  50. {
  51. Interp_1a InterpObj = new Interp_1a();
  52. }
  53.  
  54. private class CompileListener implements ActionListener
  55. {
  56. public void actionPerformed (ActionEvent e)
  57. {
  58. String exp;
  59. Interpreter InterpObj = new Interpreter();
  60.  
  61. exp = inputTextArea.getText() + " "; // get expression from input area
  62.  
  63. InterpObj.p = exp.toCharArray(); // convert input text to be read by interpreter
  64. InterpObj.counter = 0;
  65.  
  66. double num = InterpObj.AddSub(); // doing the math
  67. String str = Double.toString(num); // change result into string
  68.  
  69. outputTextArea.setText(" " + str + "\n ");
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement