Posted by:shaneangel
Posted on:2003-03-22 16:36
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import java.awt.event.*;
import java.awt.*;
public class LoginFrame extends JFrame {
LoginFrame loginFrame= null;
public LoginFrame() {
loginFrame = this;
setTitle("登录窗口");
setSize(WIDTH,HEIGHT);
LoginPanel panel = new LoginPanel();
Container contentPane = getContentPane();
contentPane.setLayout(new GridLayout());
contentPane.add("Center",panel);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(350,250,250,100);
setResizable(false);
show();
}
class LoginPanel extends JPanel {
public LoginPanel() {
userLbl = new JLabel("输入用户名:");
passwordLbl = new JLabel("输入密码:");
userTxt = new JTextField(15);
passwordTxt = new JPasswordField(15);
yesBtn = new JButton("确定");
noBtn = new JButton("退出");
yesBtn.setBounds(10,10,5,10);
setLayout(new GridLayout(3,2));
add(userLbl);add(userTxt);
add(passwordLbl);add(passwordTxt);
add(yesBtn);add(noBtn);
yesBtn.addActionListener(new
ActionListener() {
public void actionPerformed(ActionEvent event) {
}
});
noBtn.addActionListener(new
ActionListener() {
public void actionPerformed(ActionEvent event) {
MainFrame frame = new MainFrame();
loginFrame.dispose();
}
});
}
private JLabel userLbl;
private JLabel passwordLbl;
private JTextField userTxt;
private JTextField passwordTxt;
private JButton yesBtn;
private JButton noBtn;
}
private static final int WIDTH=300;
private static final int HEIGHT=120;
}