位置不对呀.....该怎么调...?
import java.awt.*;import java.awt.event.*;
public class abc extends WindowAdapter implements ActionListener
{
Frame f,f1,f2;
Button b1,b2;
TextField t1,t2;
public abc()
{
f=new Frame("Logining");
f.setSize(350,250);
f.setLayout(null);
f.setLocation(50,200); //指定框架位置
f1=new Frame("Logining failed!");
f1.setSize(250,150);
f1.setLocation(300,200);
f2=new Frame("Successed in login!");
f2.setSize(250,150);
f2.setLocation(200,100);
Panel p=new Panel();
f.add(p);
p.setBounds(50,50,300,300);
Label L1=new Label("Name:");
Label L2=new Label("Pawd:");
p.add(L1);
p.add(L2);
L1.setBounds(15,25,20,30);
L2.setBounds(30,50,20,30);
t1=new TextField(15);
t2=new TextField(15);
p.add(t1);
p.add(t2);
t1.setBounds(20,50,90,20);
t2.setBounds(90,100,90,20);
t2.setEchoChar('*'); //指定为*号显示
b1=new Button("OK");
b2=new Button("Reset");
p.add(b1);
p.add(b2);
b1.setBounds(50,90,40,20);
b2.setBounds(100,90,40,20);
b1.addActionListener(this);
b2.addActionListener(this);
f.setVisible(true);
f.addWindowListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
if(t1.getText().length()==0)
{
Panel p1=new Panel();
f1.add(p1);
p1.setBounds(20,20,130,40);
p1.add(new Label("User name doesn't in number!"));
f1.add(b2);
f1.setVisible(true);
}
if(t2.getText().length()<4)
{
Panel p2=new Panel();
f1.add(p2,"Center");
p2.setBounds(20,20,150,40);
p2.add(new Label("The password must more than four chars!"));
f1.add(b2);
f1.setVisible(true);
}
else
{
Panel p3=new Panel();
f2.add(p3);
p3.setBounds(20,20,100,40);
p3.add(new Label("Successed in login!"));
p3.add(b1);
f2.setVisible(true);
}
}
if(e.getSource()==b2)
{
f.setVisible(true);
f1.setVisible(false);
f2.setVisible(false);
}
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public static void main(String args[])
{
new abc();
}
}