JButton btnNewButton = new JButton("Pepsi");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeD();
}
});
btnNewButton.setBounds(23, 11, 80, 29);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("Sprite");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeD();
}
});
btnNewButton_1.setBounds(113, 11, 80, 29);
contentPane.add(btnNewButton_1);
JButton btnFanta = new JButton("Fanta");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeD();
}
});
这些都是调用method.This的按钮是我有一个问题,只有一个按钮点击作品,百事按钮试图致电多个按钮的一种方法,但只有一个按钮使用方法
接下来的部分是我打来的方法。它确定输入的硬币和金额是否正确。你有一个错误
public double changeD() {
JOptionPane.showMessageDialog(null, "This Product costs 1.50 EU");
String payment = JOptionPane.showInputDialog(null, "Please insert cash");
int intAmount = Integer.parseInt(payment);
double drinkPrice = 1.50;
double changeDue = intAmount - drinkPrice;
if (intAmount == 2 + 1 + .50 && intAmount > drinkPrice)
{
JOptionPane.showInputDialog(null, "Please take your product and change " + changeDue);
}
else if (intAmount != 2 + 1 + .50 || intAmount < drinkPrice)
{
JOptionPane.showMessageDialog(null, "Please insert correct amount or coins ");
}
return (Double) null;
尝试'btnNewButton_1.addActionListener'和'btnFanta.addActionListener'。你继续添加动作侦听器到同一个按钮。 –
你在暗示我改变了什么? –
对不起,我看不到整个评论,谢谢你和我现在将改变它:) –