import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class myjava3
{
public static void main(String [] agrs)
{
new myjava3_1( ) ;
}
}
class myjava3_1 extends Frame implements ActionListener
{
Label p1;
TextField p2,p3;
Button btn;
myjava3_1()
{
super("李世春的图像界面");
p1=new Label("请输入你的名字,谢谢:");
p2=new TextField(20);
p3=new TextField(35);
btn=new Button("关闭本窗口");
setLayout(new FlowLayout());
add(p1);
add(p2);
add(p3);
add(btn);
p2.addActionListener(this);
btn.addActionListener(this);
setSize(300,200);
show();
};
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==p2)
{ p3.setText(p2.getText()+",welcome !");}
else
{
dispose();
System.exit(1);
}
}
}
继承了 Frame 类
public class myjava03 extends Frame implements ActionListener
setLayout( new FlowLayout() );
input.actionListener(this)
btn.actionListener(this)
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==p2)
{ p3.setText(p2.getText()+",welcome !");}
else
{
dispose();
System.exit(1);
}
}
}
actionPerformed(ActionEvent e)
e.getSource== input 判断是否是input 输入。