-2

如果我有多个字符串和整数一起工作,如何更改 showMessageDialog 中的消息头?

这就是我可以使它工作的方法:

showMessageDialog (null, "string", "where I change the name of the box", INFORMATION_MESSAGE);

这是我无法使它工作的地方:

if (price >= 300) {
    deduction = price * 0.10;
    price = price - deduction;

    showMessageDialog (null, "Total price: ", 
                "where I want to change the        name", INFORMATION_MESSAGE 
                + price + " ." + " Received deduction: " + deduction);

Eclipse 给出以下错误消息:

“JOptionPane 类型中的方法 showMessageDialog (Component, Object, String, int) 不适用于参数 (null, String, String, String)”并建议我创建方法 showMessageDialog (Object, String, String, String)。

有什么建议么?:)

4

2 回答 2

1

INFORMATION_MESSAGE 是定义消息类型的常量。尝试使用这种方式:

showMessageDialog(null, "Total price: ", price + " ." + " Received deduction: " + deduction, INFORMATION_MESSAGE);
于 2013-10-02T15:02:30.837 回答
1

我真的不能说我理解这个问题,尽管尝试..

showMessageDialog (null, "Total price: " + 
    + price + " ." + " Received deduction: " + deduction,
    "where I want to change the name", INFORMATION_MESSAGE);
于 2013-10-02T15:03:44.213 回答