Question: The GUI won't open when I run the code below. What changes need to be made? // MyGUI.java: // Import packages import java.awt.FlowLayout; import java.awt.GridLayout;

The GUI won't open when I run the code below. What changes need to be made?

// MyGUI.java: // Import packages import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionListener; import java.util.Stack; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; // Declaare and define the class MyGUI abstract class MyGUI extends JFrame implements ActionListener { JTextField userInput; JLabel inputDescLbl, resultLbl; JPanel inputPanel, resultPanel; JButton evlBtn; Stack stk; // Define the constructor MyGUI MyGUI() { super("Tree Address Generator"); inputPanel = new JPanel(new FlowLayout()); resultPanel = new JPanel(new FlowLayout()); setLayout(new GridLayout(2, 1)); userInput = new JTextField(20); inputDescLbl = new JLabel("Enter Postfix Expression:"); evlBtn = new JButton("Construct Tree"); evlBtn.addActionListener(this); resultLbl = new JLabel("Infix Expression:", SwingConstants.LEFT); add(inputPanel); add(resultPanel); inputPanel.add(inputDescLbl); inputPanel.add(userInput); inputPanel.add(evlBtn); resultPanel.add(resultLbl); stk = new Stack<>(); } }

// MyGUI.java: // Import packages import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionListener; import java.util.Stack; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; // Declaare and define the class MyGUI abstract class MyGUI extends JFrame implements ActionListener { JTextField userInput; JLabel inputDescLbl, resultLbl; JPanel inputPanel, resultPanel; JButton evlBtn; Stack stk; // Define the constructor MyGUI MyGUI() { super("Tree Address Generator"); inputPanel = new JPanel(new FlowLayout()); resultPanel = new JPanel(new FlowLayout()); setLayout(new GridLayout(2, 1)); userInput = new JTextField(20); inputDescLbl = new JLabel("Enter Postfix Expression:"); evlBtn = new JButton("Construct Tree"); evlBtn.addActionListener(this); resultLbl = new JLabel("Infix Expression:", SwingConstants.LEFT); add(inputPanel); add(resultPanel); inputPanel.add(inputDescLbl); inputPanel.add(userInput); inputPanel.add(evlBtn); resultPanel.add(resultLbl); stk = new Stack<>(); } }

//Stack.java: // Declare and define the class Stack class Stack { private final int[] a; private int top; private final int m; public Stack(int max) { m = max; a = new int[m]; top = -1; } public void push(int key) { a[++top] = key; } public int pop() { return (a[top--]); } } // Declare and define the class Evaluation() class Evaluation { public int calculate(String s) { int n, r = 0; n = s.length(); Stack a = new Stack(n); for (int i = 0; i < n; i++) { char ch = s.charAt(i); if (ch >= '0' && ch <= '9') a.push((int) (ch - '0')); else if (ch == ' ') { } else { int x = a.pop(); int y = a.pop(); switch (ch) { case '+': r = x + y; break; case '-': r = y - x; break; case '*': r = x * y; break; case '/': r = y / x; break; default: r = 0; } a.push(r); } } r = a.pop(); return (r); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!