package assignment1_main; import javax.swing.*; import java.awt.*; import java.a
ID: 3841797 • Letter: P
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;
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?
Explanation / Answer
open static void main(String[] args) {
/TODO code application rationale here
Scanner user_input = new Scanner(System.in);
String s ;
System.out.println("Enter the Barcode:");
s = user_input.next();
String z;
System.out.println("Enter the Serial Number:");
z = user_input.next();
Irregular r = new Random();
int low = 1;
int high = 21;//Set the quantity of irregular strategies
int rand = r.nextInt(high - (low - 1)) + low;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.