JOptionPane.showInputDialog & JOptionPane.showConfirmDialog & showMessageDialog的应用

package dsfa;
import javax.swing.JOptionPane;
public class A 
{
	public static void main(String args[])
	{
		int sum = 0;
		//JOptionPane.YES_OPTION的值为0
		int option = JOptionPane.YES_OPTION;
		
		while(option == JOptionPane.YES_OPTION)
		{
			//在对话框中输入一个字符串
			String str = JOptionPane.showInputDialog("Enter an int value : ");
			//转化为数字
			int data = Integer.parseInt(str);
			
			sum += data;
			//showConfirmDialog会产生三个按键
			//YES返回值是     0
			//NO返回值是        1
			//点取消返回值是  2
			option = JOptionPane.showConfirmDialog(null,"Continue?");
		}
		//在框体中输出sum的值
		JOptionPane.showMessageDialog(null,"The sum is " + sum);
	}
}

你可能感兴趣的:(------Java基础)