我需要将Actionlistener
类型转换为整数来调用方法。有任何想法吗?
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
.