河南成教 / Java程序设计
[简答题] import java.applet.*;import javax.swing.*;import java.awt.event.*;
public class Class l extends Applet implements ActionListener{
JTextField text1,text2;
public void init(){
text1=new JTextField(10); text2=new JTextField(10);
setSize(200,100); add(text1); add(text2);
text1.addActionListener(this);
}
public void actionPerformed(Action Event e){
long n;
if(e.getSource()==text1){
n=Long.parseLong(text1.getText());
text2.setText(String.valueOf(n*n));
}
}
}
public class Class l extends Applet implements ActionListener{
JTextField text1,text2;
public void init(){
text1=new JTextField(10); text2=new JTextField(10);
setSize(200,100); add(text1); add(text2);
text1.addActionListener(this);
}
public void actionPerformed(Action Event e){
long n;
if(e.getSource()==text1){
n=Long.parseLong(text1.getText());
text2.setText(String.valueOf(n*n));
}
}
}
参考答案: