问答题

下面是一个Applet程序,其功能是接收用户输入的两个整数,比较它们的大小,并在用户按下“比较大小”按钮后,将 Applet中显示的“请先输入两个待比较的整数”,改为“两个整数中最大值是:x”,x是两个数中的最大值。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 程序运行结果如下:
import java.applet.*; import java.awt.*; import java.awt.event.*; /* <applet code=LookForMax width=800 height=400> </applet> */ public class LookForMax extends Applet implements ActionListener{ Label result ; TextField inl,in2; Button btn; int a=0,b=0,max=0; public void init() { result=new Label ("请先输入两个待比较得整数"); in1=new TextField(5); in2=new TextField(5); btn=new Button("比较大小"); add(in1); add(in2); add(btn); add(result); btn.addActionListener(supper); } public void actionPerformed(ActionEvent e){ a=Integer.parseInt(in1); b=Integer.parseInt(in2); if(a>b) max=a; else max=b; result, setText ( "两个数中最大值是:"+max); } } LookFormax.html: <html> <head> <title>A Simple Program</title> </head> <body> <applet code="LookForMax.class" width=800 height=400> </applet> </body> </html>

【参考答案】

this in1.getText() in2.getText()[解析] 本题主要考查JavaApplet程序的编写、j......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)