I have 3 TextFields. One is a totalTF the other is a tenderedTF and the last is a changeTF. I am wondering how to go about taking the total price in the totalTF and allowing the user to enter in the amount they give to the cashier into the tenderedTF, then it should work out the change once the pay button is chosen and display in the changeTF. Here is my code so far. Im trying to do the math then set the changeTF. Any help would be greatly appreciated thanks.
JButton payButton = new JButton("Pay");
payButton.setBounds(970, 569, 209, 51);
contentPane.add(payButton);
// Calculate Change
changeTF.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == payButton)
{
double change = Double.valueOf(totalTF.getText()) - Double.valueOf(tenderedTF.getText());
changeTF.setText(String.valueOf(change));
}
}
});
tenderedTF.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == payButton)
{
double change = Double.valueOf(totalTF.getText()) - Double.valueOf(tenderedTF.getText());
changeTF.setText(String.valueOf(change));
}
}
});