学生成绩管理系统实战练习之登陆界面
开发软件:eclips
使用插件:windowsbuilder
代码风格:Swing
源码如下
package UI;import UI.MySystemUI;import java.awt.EventQueue;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.border.LineBorder;import java.awt.Color;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.Font;import javax.swing.JPasswordField;import javax.swing.JFormattedTextField;import java.awt.Button;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;publicclassLoginextendsJFrame{/**
*
*/privatestaticfinallong serialVersionUID =1L;private JPanel LoginPanel;private JPasswordField passwordField;/**
* Launch the application.
*/publicstaticvoidmain(String[] args){
EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{
Login frame =newLogin();
frame.setVisible(true);}catch(Exception e){
e.printStackTrace();}}});}/**
* Create the frame.
*/publicLogin(){/**
* 创建并设置登陆界面主面板
*/setTitle("学生成绩管理系统登陆界面(1.0)");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100,100,485,343);setResizable(false);//禁止最大化setLocationRelativeTo(null);//居中/**
* 创建主布局Panel
*/
LoginPanel =newJPanel();
LoginPanel.setBorder(newLineBorder(newColor(0,0,0)));setContentPane(LoginPanel);
LoginPanel.setLayout(null);/**
* 添加背景图片到JLabel中
*/
ImageIcon backimg;
backimg=newImageIcon("E:\\JavaECode\\GUIofManagementSystem\\src\\Picture\\Back.jpg");/**
* 创建一个账号标签
*/
JLabel IDLabel =newJLabel("账 号:");
IDLabel.setFont(newFont("新宋体", Font.BOLD,20));
IDLabel.setForeground(Color.LIGHT_GRAY);
IDLabel.setBounds(49,170,91,38);
IDLabel.setOpaque(false);
LoginPanel.add(IDLabel);/**
* 创建一个密码标签
*/
JLabel PasswordLabel =newJLabel("密 码:");
PasswordLabel.setOpaque(false);
PasswordLabel.setForeground(Color.LIGHT_GRAY);
PasswordLabel.setFont(newFont("新宋体", Font.BOLD,20));
PasswordLabel.setBounds(49,221,91,38);
LoginPanel.add(PasswordLabel);/**
* 登陆文本框
*/final JFormattedTextField idTextField =newJFormattedTextField();
idTextField.setForeground(Color.LIGHT_GRAY);
idTextField.setToolTipText("");
idTextField.setText("请输入您的账号");
idTextField.setBounds(143,175,227,33);// 添加账号框事件
idTextField.addMouseListener(newMouseListener(){publicvoidmouseReleased(MouseEvent e){// TODO 当用户松开鼠标按钮时发生}publicvoidmousePressed(MouseEvent e){// TODO 当用户按下鼠标按钮时发生.if(idTextField.getText().equals("请输入您的账号"))
idTextField.setText(null);
idTextField.setForeground(Color.BLACK);}publicvoidmouseExited(MouseEvent e){// TODO 当鼠标离开你所监听的组件时发生.}publicvoidmouseEntered(MouseEvent e){// TODO 当鼠标离开当前组件并进入你所监听的组件时激活事件.}publicvoidmouseClicked(MouseEvent e){// TODO 鼠标按下后松开}});
LoginPanel.add(idTextField);/**
* 密码框
*/
passwordField =newJPasswordField();
passwordField.setBounds(143,221,227,33);
LoginPanel.add(passwordField);/**
* 登陆按钮
*/
Button StdBtn =newButton("\u7BA1\u7406\u5458\u767B\u9646");
StdBtn.addActionListener(newActionListener(){@SuppressWarnings("deprecation")publicvoidactionPerformed(ActionEvent e){if(idTextField.getText().equals("1")&&passwordField.getText().equals("1")){/**
* 登陆成功后自动关闭登陆界面进入到信息界面
*/
System.out.print("登陆成功");dispose();
MySystemUI F=newMySystemUI();
F.setVisible(true);}else{
JOptionPane.showMessageDialog(null,"账户或密码错误,登陆失败!",null, JOptionPane.ERROR_MESSAGE);}}});
StdBtn.setForeground(Color.DARK_GRAY);
StdBtn.setFont(newFont("宋体", Font.BOLD,17));
StdBtn.setBackground(Color.LIGHT_GRAY);
StdBtn.setBounds(178,266,110,33);
LoginPanel.add(StdBtn);/**
* 背景图片的设置
*/
JLabel BackgroundLabel =newJLabel(backimg);
BackgroundLabel.setBounds(0,0,482,309);
LoginPanel.add(BackgroundLabel);}}
运行结果:
本文转载自: https://blog.csdn.net/captainpirate/article/details/90450896
版权归原作者 Winner Is LaVie 所有, 如有侵权,请联系我们删除。
版权归原作者 Winner Is LaVie 所有, 如有侵权,请联系我们删除。