Question
package assignment1_main; import javax.swing.*; import java.awt.*; import java.awt.event.* ; /** * * @author willi public class Calculator extends JFrame { JTextField xInput, y Input, answer;
package assignment1_main;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*
; /** * * @author willi
public class Calculator extends JFrame {
JTextField xInput, y
Input, answer;
public Calculator() {
super();
init();
}
/** * */
private void init() {
JButton jbtadd = new JButton("+");
JButton jbtsub = new JButton("-");
JButton jbtmul = new JButton("x");
JButton jbtdiv = new JButton("/");
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(1, 4))
;p1.add(jbtadd);
p1.add(jbtsub);
p1.add(jbtmul);
p1.add(jbtdiv);
JLabel firstNum = new JLabel("Enter first number");
JTextField xInput = new JTextField("", 3);
JLabel secNum = new JLabel("Enter second number");
JTextField yInput = new JTextField("", 3);
JLabel equals = new JLabel("Answer:");
JTextField answer = new JTextField("", 8)
; MultiplyButton multiply = new MultiplyButton();
jbtmul.addActionListener(multiply);
DivideButton divide = new DivideButton();
jbtdiv.addActionListener(divide);
AddButton add = new AddButton();
jbtadd.addActionListener(add);
SubtractButton subtract = new SubtractButton();
jbtsub.addActionListener(subtract);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(firstNum); p2.add(xInput);
p2.add(secNum); p2.add(yInput)
; p2.add(equals); p2.add(answer);
p2.add(p1); add(p2);
xInput.requestFocus();
}
private class DivideButton implements ActionListener {
@Override public void actionPerformed(ActionEvent e) {
}
}
private class MultiplyButton implements ActionListener {
@Override public void actionPerformed(ActionEvent e)
{
}
}
private class AddButton implements ActionListener {
@Override public void actionPerformed(ActionEvent e) {
}
}
private class SubtractButton implements ActionListener {
@Override public void actionPerformed(ActionEvent e) {
}
}
}
Now how do I get the input to display in the answer textField?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started