2012年5月31日 星期四

Java Basic(50)-Graphical User Interface GUI


import javax.swing.JOptionPane; 入使用JOptionPane


class apples{
public static void main(String[] args){
String fn = JOptionPane.showInputDialog("Enter first number");
String sn = JOptionPane.showInputDialog("Enter second number");
int num1 = Integer.parseInt(fn); 改變字符串到整數
int num2 = Integer.parseInt(sn); 改變字符串到整數
int sum = num1 + num2;
JOptionPane.showMessageDialog(null, "The answer is " +sum, "the title", JOptionPane.PLAIN_MESSAGE);
}
}

這是運行時的結果:




沒有留言:

張貼留言