图形用户界面程序填空。界面效果:姓名、学号两个标签之后两个文本行。在文本行填入姓名和学号后,单击按钮“提交”,学号从上往下掉,姓名从左往右移动。注意有的空需将不完整的 Java 保留字补齐
import java.applet.Applet;
import java.awt.1; //(1)
import java.awt.event.2; //(2)
public class NameDrop extends Applet implements 3,ActionListener{ //(3)
private int x =0;
private int y =0;
private Thread 4 ; //(4)
private boolean b = false ;
private Button button ;
private TextField textFieldName ;
private TextField textFieldID ;
private String name ;
private String ID ;
private Label LabelName ;
private Label LabelID ;
public void init( ){
this.setSize(300,300);
button = new Button( " 提交 " );
textFieldName = new TextField(10);
textFieldID = new TextField(10);
button .addActionListener( 5 ); //(5)
LabelName = new Label( " 姓名 " );
LabelID = new Label( " 学号 " );
this.add( button );
this.add( LabelName );
this.add( textFieldName );
this.add( LabelID );
this.add( textFieldID );
}
public void 6{ //(6)
if ( t == null ){
t = new 7( this ); //(7)
t .start( );
}
}
public void stop( ){
if ( t != null ){
t .interrupt( );
t = null ;
}
}
public void paint(8 g){ //(8)
if ( b ){
x = x +1;
y = y +1;
g.drawString( name , x ,80);
g.drawString( ID ,50, y );
}
}
public void run( ) {
while ( t != null ){
9( ); //(9)
try {
t .10(20); //(10)
} catch (InterruptedException e){
11 ; //(11)
}
}
}
public void actionPerformed(ActionEvent e) {
if (e.12 == button ){ //(12)
b = true ;
name = textFieldName . 13( ); //(13)
ID = textFieldID . getText( );
}
}