【发布时间】:2016-12-15 08:22:04
【问题描述】:
我们最近在课堂上查看了对话框并分配了家庭作业。
任务是设计和实现一个应用程序,该应用程序使用对话框获取两个整数值(每个值一个对话框)并显示这些值的总和和乘积。使用另一个对话框询问用户是否要处理另一对值。
到目前为止,我尝试执行该项目,但在显示答案的一行代码中遇到问题。我正在使用 NetBeans IDE,并使用了显示方法 JOptionPane.showConfirmDialog 来显示我的答案。它一直给我一个错误,说“没有找到适合showMessageDialog 的方法”。我试图使用System.out.println,但它也给了我错误,所以我回到了这个方法。你能解释一下如何修复它以及为什么我的代码是错误的吗?
这是我目前的代码:
package DialogBoxes;
import javax.swing.JOptionPane;
/**
*
* @author Tony
*/
public class SumProduct {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String askNum1, askNum2, answerSum, answerPro;
int num1, num2, repeat;
do
{
askNum1 = JOptionPane.showInputDialog ("Enter your first integer:");
num1 = Integer.parseInt(askNum1);
askNum2 = JOptionPane.showInputDialog("Enter your second integer:");
num2 = Integer.parseInt(askNum2);
answerSum = "The sum is: " + ((num1 + num2));
answerPro = "The product is: " + ((num1 * num2));
JOptionPane.showMessageDialog(null, answerSum, answerPro);
repeat = JOptionPane.showConfirmDialog(null, "Would you like to test another set of numbers?");
}
while (repeat == JOptionPane.YES_OPTION);
}
}
【问题讨论】:
标签: java swing dialog joptionpane