import java.applet.Applet
import java.awt.*
import java.awt.event.*
public class Sum extends Applet implements ActionListener {
TextField text1, text2, text3
Label lb1, lb2, lb3
public void init() {
text1 = new TextField(25)
text2 = new TextField(25)
text3 = new TextField(25)
lb2 = new Label("请输入第二个整数:")
lb3 = new Label("他们的和:")
add(lb1)
add(text1)
add(lb2)
add(text2)
add(lb3)
add(text3)
text1.addActionListener(this)
text2.addActionListener(this)
}
public void paint(Graphics g) {
g.drawString("输出2个数,如果他们的和大于5,则蚂岁哗按回雀搜车键闷行输出他们的和", 10, 100)
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == text1 || e.getSource() == text2
|| e.getSource() == text3) {
int number1, number2, sum
try {
number1 = Integer.valueOf(text1.getText()).intValue()
number2 = Integer.valueOf(text2.getText()).intValue()
sum = number1 + number2
if (sum >5) {
text3.setText("" + sum)
}
} catch (NumberFormatException event) {
text3.setText("请输入整数")
}
} else {
System.exit(0)
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)