java登陆界面_登陆界面设计

这篇博客展示了如何使用Java实现一个图书管理系统的登录界面。代码包括了界面布局、组件设置、事件监听等功能,如用户名和密码输入框、忘记密码和注册链接等,并通过AdminDao接口进行登录验证。
摘要由CSDN通过智能技术生成

[java]代码库//登陆界面

package com.view;

import java.awt.Color;

/**

* 登陆

* @author Administrator

*

*/

public class InTo extends JFrame implements ActionListener,MouseListener{

/**

* 成员变量

*/

private static final long serialVersionUID = 1L;

//北部

private JLabel topImg ;

//中部

private JPanel panel1;

private JLabel nameLab,pswLab;

private JTextField nameTex;

private JPasswordField pswTex;

JLabel forgetLab;

private JLabel insertLab;

private JButton intoBut;

//监听处理

private AdminDao admin;

private JLabel alertLab;

/**

* 入口

*/

public static void main(String[] args) {

try {

// String lookAndFeel =

// UIManager.getCrossPlatformLookAndFeelClassName();

UIManager.setLookAndFeel(new BernsteinLookAndFeel());

//UIManager.setLookAndFeel(new McWinLookAndFeel());

//UIManager.setLookAndFeel(new MetalLookAndFeel());

} catch (Exception e) {

}

new InTo();

}

/**

* 初始化

*/

public InTo() {

admin=new AdminDao();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setTitle("鑫鑫图书管理登陆");

this.setUndecorated(true);//去掉窗口的装饰

this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);设置为简单对话窗口

setIconImage(Toolkit.getDefaultToolkit().getImage("QQ图标/a.png"));

setSize(450, 340);

this.setLocationRelativeTo(null);

getContentPane().setLayout(null);

JLabel alert = new JLabel("鑫 鑫 图 书 管 理 系 统DA BING TU SHU GUAN LI XING TONG");

alert.setBounds(221, -11, 300, 83);

getContentPane().add(alert);

topImg= new JLabel(new ImageIcon("image/图书馆登陆.jpg"));

topImg.setBounds(0, 0, 450, 120);

getContentPane().add(topImg);

panel1 = new JPanel();

panel1.setBounds(0, 120, 450, 220);

panel1.setLayout(null);

nameLab = new JLabel("用户名:");

nameLab.setFont(MySetFont.f6);

nameLab.setBounds(46, 10, 69, 35);

panel1.add(nameLab);

nameTex = new JTextField();

nameTex.setBounds(135, 10, 155, 35);

panel1.add(nameTex);

nameTex.addActionListener(this);//监听2

nameTex.setColumns(10);

pswLab = new JLabel("密码:");

pswLab.setFont(MySetFont.f6);

pswLab.setBounds(46, 60, 69, 35);

panel1.add(pswLab);

pswTex = new JPasswordField();

pswTex.setBounds(135, 60, 155, 35);

pswTex.addActionListener(this);//监听2

panel1.add(pswTex);

forgetLab = new JLabel("忘记密码");

forgetLab.setForeground(Color.red);

forgetLab.setFont(MySetFont.f3);

forgetLab.setHorizontalAlignment(SwingConstants.CENTER);

forgetLab.setBounds(300, 10, 108, 35);

forgetLab.addMouseListener(this);//监听1

panel1.add(forgetLab);

insertLab = new JLabel("注册账号");

insertLab.setHorizontalAlignment(SwingConstants.CENTER);

insertLab.setBounds(300, 60, 108, 35);

insertLab.setFont(MySetFont.f3);

insertLab.setForeground(Color.blue);

insertLab.addMouseListener(this);//监听1

panel1.add(insertLab);

alertLab = new JLabel();

alertLab.setHorizontalAlignment(SwingConstants.LEFT);

alertLab.setForeground(Color.RED);

alertLab.setFont(MySetFont.f3);

alertLab.setBounds(135, 95, 273, 35);

panel1.add(alertLab);

intoBut = new JButton("登  陆");

intoBut.setFont(MySetFont.f3);

intoBut.setBounds(135, 140, 155, 37);

intoBut.addMouseListener(this);//监听1

intoBut.addActionListener(this);

panel1.add(intoBut);

getContentPane().add(panel1);

this.setVisible(true);

}

/鼠标监听1

@Override

public void mouseClicked(MouseEvent de) {

//点击

if(de.getSource()==forgetLab){

new InTo_Forget();

this.dispose();

}else if(de.getSource()==insertLab){

//注册

this.dispose();

}

}

@Override

public void mouseEntered(MouseEvent de) {

// 进入

if(de.getSource()==forgetLab){

forgetLab.setFont(MySetFont.f1);

}else if(de.getSource()==insertLab){

insertLab.setFont(MySetFont.f1);

}else if(de.getSource()==intoBut){

intoBut.setForeground(Color.red);

}

}

@Override

public void mouseExited(MouseEvent de) {

// 移除

if(de.getSource()==forgetLab){

forgetLab.setFont(MySetFont.f3);

}else if(de.getSource()==insertLab){

insertLab.setFont(MySetFont.f3);

}else if(de.getSource()==intoBut){

intoBut.setForeground(Color.black);

}

}

@Override

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

//基本监听2

@Override

public void actionPerformed(ActionEvent de) {

String name=nameTex.getText();

String psw=new String(pswTex.getPassword());

if(de.getSource()==nameTex){

pswTex.requestFocus();//获得焦点

}else if(de.getSource()==pswTex){

doPD(name,psw);

}else if(de.getSource()==intoBut){

doPD(name,psw);

}

}

/**

* 登陆的判断

*/

public void doPD(String name,String psw){

AdminPoJo pojo=new AdminPoJo();

if(StringUtil.isNotNull(name)&&StringUtil.isNotNull(psw)){

pojo.setName(name);

pojo.setPassword(psw);

AdminPoJo pojo1=admin.doInTo(pojo);

if(pojo1!=null){

//ok登陆

alertLab.setText("ok");

new Menu();

this.dispose();

}else{

//no

alertLab.setText("登陆失败");

}

}else{

//填写

alertLab.setText("填写");

}

}

}

694748ed64b9390909c0d88230893790.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值