eclipse编写一个简单实用的登陆界面
花了点时间写了一个简单的页面:package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UserInterface extends JFrame implements WindowListener{
JFrame jf;
JPanel jpan1,jpan2,jpan3;
JLabel username,password,lspace;
JTextField user,pass;
JButton login,register;
public void go(){
jf=new JFrame("UserInterface");
jf.setSize(350, 250);
jf.setResizable(false);
jf.setLayout(new GridLayout(6,1,0,5));
jpan1=new JPanel();
jpan2=new JPanel();
jpan3=new JPanel();
username=new JLabel("Username");
password=new JLabel("Password");
user=new JTextField(12);
pass=new JTextField(12);
login=new JButton("Login");
register=new JButton("Register");
jpan1.setSize(200, 50);
jpan1.add(username);
jpan1.add(user);
jpan2.setSize(200, 50);
jpan2.add(password);
jpan2.add(pass);
jpan3.setLayout(new FlowLayout(FlowLayout.CENTER,20,0));
jpan3.add(login);
jpan3.add(register);
lspace=new JLabel();
jf.add(lspace);
jf.add(jpan1);
jf.add(jpan2);
lspace=new JLabel();
jf.add(lspace);
jf.add(jpan3);
lspace=new JLabel();
jf.add(lspace);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
public static void main(String[] args){
UserInterface ui=new UserInterface();
ui.go();
}
public void windowDeactivated(WindowEvent e){
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}