如何将数字添加到整数?
How to add numbers to integer?
按钮必须将整数加 50 但不是 .我不太了解 Jframe,所以请帮帮我。
int money = 0;
...
JButton verlan = new JButton("50 kr\u015F");
verlan.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int moremoney = money + 50;
String x=Integer.toString(moremoney);
textArea.setText(x + " cent");
}
});
在您的 ActionListener
中,您定义了一个新变量,您将 money
的值与 50 相加,但是您永远不会更新 money
的初始值。相反,您可以更新金钱,但是您必须确保该变量在 ActionListener
的范围内可用,例如通过将其声明为成员变量。
private int money = 0;
...
JButton verlan = new JButton("50 kr\u015F");
verlan.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
money += 50;
String x=Integer.toString(money);
textArea.setText(x + " cent");
}
});
按钮必须将整数加 50 但不是 .我不太了解 Jframe,所以请帮帮我。
int money = 0;
...
JButton verlan = new JButton("50 kr\u015F");
verlan.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int moremoney = money + 50;
String x=Integer.toString(moremoney);
textArea.setText(x + " cent");
}
});
在您的 ActionListener
中,您定义了一个新变量,您将 money
的值与 50 相加,但是您永远不会更新 money
的初始值。相反,您可以更新金钱,但是您必须确保该变量在 ActionListener
的范围内可用,例如通过将其声明为成员变量。
private int money = 0;
...
JButton verlan = new JButton("50 kr\u015F");
verlan.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
money += 50;
String x=Integer.toString(money);
textArea.setText(x + " cent");
}
});