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
。