我正在尝试使用 Java AWT 制作登录表单。我成功了。但是当我点击按钮时,除了“Pin”之外的所有文件都显示在正确的位置。“Pin”显示在与“Name”相同的维度上。我无法重新定位“Pin”文本字段。为什么?这是代码:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Loginform extends Frame implements ActionListener
{
Label l1=new Label("Name");
Label l2=new Label("Street");
Label l3=new Label("City");
Label l4=new Label("Pin");
Label l5=new Label(" ");
Label l6=new Label(" ");
Label l7=new Label(" ");
Label l8=new Label(" ");
TextField t1=new TextField();
TextField t2=new TextField();
TextField t3=new TextField();
TextField t4=new TextField();
Button b= new Button("Submit");
public Loginform()
{ add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(b);
add(l5);
add(l6);
add(l7);
add(l8);
l1.setBounds(20,45,70,20);
t1.setBounds(180,45,200,20);
l2.setBounds(20,95,70,20);
t2.setBounds(180,95,200,20);
l3.setBounds(20,135,70,20);
t3.setBounds(180,135,200,20);
l4.setBounds(20,175,70,20);
t4.setBounds(180,175,200,20);
l5.setBounds(20,300,70,20);
l6.setBounds(20,320,70,20);
l7.setBounds(20,340,70,20);
l8.setBounds(20,360,70,20);
b.setBounds(410,245,70,20);
b.addActionListener(this);
addWindowListener(new mwa());
}
public void actionPerformed(ActionEvent e)
{
l5.setText("Name: "+t1.getText());
l6.setText("Street: "+t2.getText());
l7.setText("City: "+t3.getText());
l8.setText("Pin: "+t4.getText());
}
public static void main(String s[])
{
Loginform l=new Loginform();
l.setSize(new Dimension(600,600));
l.setTitle("REGISTRATION");
l.setVisible(true);
}
}
class mwa extends WindowAdapter
{ public mwa(){}
public void windowClosing(WindowEvent e)
{ System.exit(0);
}
}