代码如下:
import java.awt.Graphics; import javax.swing.*; //*********Found********** public class Java_3 extends ____________________ { double sum; //存和的变量 //*********Found********** public void __________________() { String firstNumber, //输入第1个字符串格式的数 secondNumber; //输入第2个字符串格式的数 double number1, //加数 number2; //被加数 //读入第1个输入的数 firstNumber = JOptionPane.showInputDialog( "Enter first floating-point value"); //读入第2个输入的数 secondNumber = JOptionPane.showInputDialog( "Enter second floating-point value"); //将字符串数据转换成双字长类型 number1 = Double.parseDouble(firstNumber); number2 = Double.parseDouble(secondNumber); //数据相加 sum = number1 + number2; } public void paint(Graphics g) { //用g.drawString给结果 g.drawRect(15, 10, 270, 20); g.drawString("数相加之和为:" + sum, 25, 25); } }