i am trying to write a code where you have three fields pop up, and it will multiply the first two inputs and auto-update the third field and change the value and the text property of the last field while you enter the values into the first fields?
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Solver implements ActionListener {
void actionPerformed(ActionEvent E){
JTextField xField = new JTextField(5);
JTextField yField = new JTextField(5);
JTextField zField = new JTextField(5);
JPanel myPanel = new JPanel();
myPanel.add(new JLabel("x:"));
myPanel.add(xField);
myPanel.add(Box.createHorizontalStrut(15));
myPanel.add(new JLabel("y:"));
myPanel.add(yField);
myPanel.add(Box.createHorizontalStrut(15));
myPanel.add(new JLabel("z:"));
myPanel.add(zField);
int result = JOptionPane.showConfirmDialog(null, myPanel,
"please enter X and Y value", JOptionPane.OK_CANCEL_OPTION);
double x = Double.parseDouble(xField.getText());
double y = Double.parseDouble(yField.getText());
if(result == JOptionPane.OK_OPTION) {
System.out.println(x+10.0);
System.out.println(y + 10);
}
}
}
right now i have it printing both initial values added by 10 just to be sure they are set to doubles, but if someone could help me to make the zField change to whatever arithmetic that would be appreciated(and if someone can get rid of the error with the actionPerformed conflicting with ActionLister that would be greatly appreciated as well.)