1
我需要将Actionlistener
类型转换为整数来调用方法。 任何想法?将Actionlistener类型转换为整数java
import javax.swing.*;
import java.awt.*;
/**
* sold by pound
*/
public class CandyPanel extends JPanel {
public CandyPanel() {
// Create a GridLayout manager with
// two rows and one column.
setLayout(new GridLayout(1, 1));
// Create the radio buttons.
JPanel gummyBears = new JPanel(new BorderLayout());
// Add a border around the panel.
setBorder(BorderFactory.createTitledBorder("Gummy Bears"));
// Add the JPanel to the panel.
add(gummyBears);
}
/**
* returns the total cost of the item based on the
* number of units purchased
* @param number the number of units purchased
* @return the total cost of those units
*/
public double getCost(int number) {
double total = number * 2.00;
return total;
}
/**
* Prints the ordered item
* @param amount the number of units purchased
* @param cost the total cost of those units
*/
public void printOrderItem(int amount, double cost){
JOptionPane.showMessageDialog(null, amount + " Gummy Bears at $2.00/pound = $" + cost + ".");
}
}
这是将需要转换的int
的方法。
public double getCost(int number) {
double total = number * 2.00;
return total;
}
我试着做parseInt
在线研究,但它不与ActionEvent
工作。
'e'不是一个字符串。整数值应该来自哪里? –
是的,我意识到它不是一个字符串。 整数值应该是用户输入的内容。 我会问有多少需要和用户会给我输入。问题是,ActionEvent是监听器,所以我希望有一个临时值来存储解析的ActionEvent类型。 会getText()的工作? – user1283885
输入应该去哪里?有没有文本框?目前,您提供的代码中没有任何地方提到用户输入数字的方式。 –