java登录界面代码

来源:互联网 发布:数据库表的设计的规范 编辑:程序博客网 时间:2024/06/11 21:02
//登录界面package com.gui;import java.sql.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.List;import com.DateSystem.*;public class Landing extends JFrame implements ActionListener{//声明创建组建JLabel lbl_name,lbl_password;JTextField text_name;JPasswordField password;JCheckBox box_rember,box_auto;JButton button_submit,button_zhuce;JPanel jPanel;private ImageIcon background;//背景图片public Landing() {super("用户登录");lbl_name = new JLabel("用户名:");lbl_password = new JLabel("密    码:");text_name = new JTextField("",30);password = new JPasswordField();button_submit = new JButton("登录");button_zhuce = new JButton("注册");jPanel = new JPanel();box_rember = new JCheckBox("记住密码");box_auto = new JCheckBox("自动登录");background = new ImageIcon("g:\\java\\BaoDing_Shoop\\img\\bg2.jpg");// 背景图片G:\java\BaoDing_Shoop\src\com\guiJLabel label = new JLabel(background);// 把背景图片显示在一个标签里面// 把标签的大小位置设置为图片刚好填充整个面板label.setBounds(0, 0, background.getIconWidth(),background.getIconHeight());// 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明try{//jPanel = (JPanel) this.getContentPane();}catch(IllegalArgumentException ie){System.out.print("你啊哈");}jPanel.setOpaque(false);Font font = new Font("Serif",Font.BOLD,20);lbl_name.setFont(font);lbl_password.setFont(font);this.getLayeredPane().setLayout(null);// 把背景图片添加到分层窗格的最底层作为背景this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setSize(400,300);this.setLocationRelativeTo(null);this.setVisible(true);this.setResizable(false);jPanel.setLayout(null);lbl_name.setBounds(50, 30, 150, 50);lbl_password.setBounds(50, 90, 150, 50);text_name.setBounds(120,45, 200, 25);password.setBounds(120,105,200,25);box_rember.setBounds(120, 155, 100, 20);box_auto.setBounds(220, 155, 100, 20);button_submit.setBounds(100,200,60, 30);button_zhuce.setBounds(240, 200, 60, 30);jPanel.add(button_submit);jPanel.add(button_zhuce);jPanel.add(lbl_name);jPanel.add(lbl_password);jPanel.add(text_name);jPanel.add(password);//jPanel.add(box_rember);//jPanel.add(box_auto);add(jPanel);addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});//注册监听button_submit.addActionListener(this);button_zhuce.addActionListener(this);text_name.addActionListener(this);password.addActionListener(this);//box_auto.addActionListener(this);//box_rember.addActionListener(this);}public static void main(String[] args) {Landing landing = new Landing();}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubString buttString = e.getActionCommand();//返回按钮值Boolean flag_remeber= box_rember.isSelected();//判断记住密码是否被选中Boolean flag_auto=box_auto.isSelected();if (buttString.equals("登录")) {System.out.println("登录");String name = text_name.getText().trim(); String pass =String.valueOf(password.getPassword());String sql = "select * from userdata where username='"+name+"' and userpassword='"+pass+"'";Userdate uda=new Userdate();List<User> list=uda.findUser(sql);if (list.size()>0) {JOptionPane.showMessageDialog(this, name+",欢迎登陆!");Main mGui=new  Main();mGui.setVisible(true);this.dispose();}else {JOptionPane.showMessageDialog(this, "无法登录,请重新输入用户名和密码");this.text_name.setText("");this.password.setText("");}if (box_rember.isSelected()) {System.out.println("记住密码");}else {System.out.println("没有记住密码");}if (box_auto.isSelected()) {System.out.println("自动登录");}else {System.out.println("没有自动登录");}}else {System.out.println("注册");Register register = new Register();register.setSize(600, 470);register.setLocationRelativeTo(null);register.setVisible(true);register.setResizable(false);}}} 

原创粉丝点击