package com.sxt.studentsystem;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame {
private LoginActionListener myActionListener;
private JTextField txtName;
private JPasswordField txtPassword;
public JTextField getTxtName() {
return txtName;
}
public void setTxtName(JTextField txtName) {
this.txtName = txtName;
}
public JPasswordField getTxtPassword() {
return txtPassword;
}
public void setTxtPassword(JPasswordField txtPassword) {
this.txtPassword = txtPassword;
}
public LoginFrame() {
myActionListener = new LoginActionListener(this);// 创建侦听器
this.setLayout(null);// 默认的布局样式
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 设置位置,居中
Dimension SreenSize = Toolkit.getDefaultToolkit().getScreenSize();
int x = (SreenSize.width - 400) / 2;
int y = (SreenSize.height - 300) / 2;
this.setBounds(x, y, 400, 300);// 设置大小,位置
// 设置主标题
JLabel labMain = new JLabel("欢迎进入学生管理系统");
labMain.setBounds(120, 20, 200, 25);
labMain.setFont(new Font("宋体", Font.BOLD, 15));// 字体大小格式
this.getContentPane().add(labMain);
// 设置背景图片
JLabel labBackgImage = new JLabel(new ImageIcon("images/back.jpg"));
labBackgImage.setBounds(0, 0, 400, 300);
this.getLayeredPane()
.add(labBackgImage, new Integer(Integer.MIN_VALUE));// 设置深度
((JPanel) getContentPane()).setOpaque(false);
//
JLabel labName = new JLabel("姓名:");
labName.setBounds(120, 60, 50, 25);
this.getContentPane().add(labName);
JLabel labPassword = new JLabel("密码:");
labPassword.setBounds(120, 100, 50, 25);
this.getContentPane().add(labPassword);
// 输入用户名
txtName = new JTextField("皮锋");
txtName.setBounds(160, 60, 100, 25);
this.getContentPane().add(txtName);
// 输入密码
txtPassword = new JPasswordField("123456");
txtPassword.setBounds(160, 100, 100, 25);
this.getContentPane().add(txtPassword);
// 按钮
JButton btnLogin = new JButton("登录");
btnLogin.setBounds(120, 160, 60, 25);
// 添加一个标签
btnLogin.setActionCommand("login");
this.add(btnLogin);
// 处理事件
btnLogin.addActionListener(this.myActionListener);
JButton btnCantel = new JButton("取消");
btnCantel.setBounds(220, 160, 60, 25);
// 添加一个标签
btnCantel.setActionCommand("exit");
this.add(btnCantel);
btnCantel.addActionListener(this.myActionListener);
// 窗体事件
this.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
Date date = new Date();
SimpleDateFormat d = new SimpleDateFormat("yyy年MM月dd日hh:mm:ss");
String sDate = d.format(date);
LoginFrame.this.setTitle(sDate);
}
});
// 鼠标事件
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
int x = e.getX();
int y = e.getY();
String s = new String(x + "," + y);
// txtName.setText(s);
}
});
this.setVisible(true);
}
}
评论0
最新资源