×

自动登录javaswing

自动登录javaswing(SWT做出像QQ那种的保存密码和自动登录的功能)

admin admin 发表于2024-03-03 18:53:20 浏览31 评论0

抢沙发发表评论

大家好,今天小编来为大家解答以下的问题,关于自动登录javaswing,SWT做出像QQ那种的保存密码和自动登录的功能这个很多人还不知道,现在让我们一起来看看吧!

本文目录

SWT做出像QQ那种的保存密码和自动登录的功能

是写在配置文件当中的, 给你一个参考,这个是我们代码中的配置文件,我们用swing开发的一个软件, 直接用java.util.Properties 中的方法, 自己写一个配置文件就可以了。import java.util.Properties;public class UserConfig{private static Properties sProperties = new Properties();private static final String PROPERTY_FILE_NAME = "user.properties";private static File sFile = new File(PROPERTY_FILE_NAME);static {try {if (!sFile.exists()) {sFile.createNewFile();}sProperties = new Properties();FileInputStream fis = new FileInputStream(sFile);sProperties.load(fis);fis.close();} catch (Exception e) {e.printStackTrace();}}public static int getIntValue(String key) {String s = sProperties.getProperty(key);int ret = INVALID_VALUE;try {ret = Integer.valueOf(s);} catch (NumberFormatException nfe) {//nfe.printStackTrace();}return ret;}public static void setIntValue(String key, int value) {String v = Integer.toString(value);sProperties.setProperty(key, v);}}

求高手用JAVA帮我写一个跟QQ2010经典型登陆界面一样的程序

package QQtable;import javax.swing.*;import java.awt.FlowLayout;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.event.*;import java.net.*;import java.io.*;public class QQtable extends JFrame{//北边JLabel jl=null;//中间JPanel jp1_left=null;JPanel jp2_right=null;JLabel jl2=null;JLabel jl3=null;JCheckBox jcb1=null;JCheckBox jcb2=null; JTextField jtf1=null;JPasswordField jpf=null;//南边JPanel jp3=null;JButton jb1=null;JButton jb2=null;public static void main(String args){QQtable qqt=new QQtable();}public QQtable(){//北边jl=new JLabel(new ImageIcon("C:\\Documents and Settings\\Administrator\\桌面\\QQpicture\\未命名_r2_c2.jpg"));this.add(jl,"North");//中间] jp1_left=new JPanel();jl2=new JLabel(new ImageIcon("C:\\Documents and Settings\\Administrator\\桌面\\QQpicture\\未命名_r5_c4.jpg"));jp1_left.add(jl2);//jp1_left.add(jl);jp2_right=new JPanel(new GridLayout(3,2));jtf1=new JTextField(10);jl2=new JLabel("注册",JLabel.CENTER);jl3=new JLabel("找回",JLabel.CENTER);jpf=new JPasswordField(10);jcb1=new JCheckBox("记住密码");jcb2=new JCheckBox("自动登录");jp2_right.add(jtf1);jp2_right.add(jl2);jp2_right.add(jpf);jp2_right.add(jl3);jp2_right.add(jcb1);jp2_right.add(jcb2); //南边jp3=new JPanel();jb1=new JButton("设置");jb2=new JButton("安全登录"); jp3.add(jb1,"left");jp3.add(jb2,"right");this.setLayout(new FlowLayout()); this.add(jp1_left,"West");this.add(jp2_right,"East");this.add(jp3,"South");this.setIconImage((new ImageIcon("C:\\Documents and Settings\\Administrator\\桌面\\QQpicture\\未命名.jpg")).getImage());this.setTitle("泽明qq2011");this.setSize(300,250);this.setVisible(true);} }图片自己找我运行的效果如你的图:

java用手工布局设置QQ登录界面

view plaincopypackage ibees.qq; import java.awt.BorderLayout; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; /** * 仿QQ登录界面,仅供学习参考,涉及到的有窗口居中、JPanel、LayoutManager的使用 * @author hhzxj2008 * */ public class QQLoginView extends JFrame { /** * */ private static final long serialVersionUID = -5665975170821790753L; public QQLoginView() { initComponent(); } private void initComponent() { setTitle("用户登录"); //设置LOGO URL image = QQLoginView.class.getClassLoader().getResource("ibees/qq/images/year.jpg");//图片的位置 JLabel imageLogo = new JLabel(new ImageIcon(image)); add(imageLogo,BorderLayout.NORTH); //QQ号和密码 JPanel jp = new JPanel(); JPanel jpAccount = new JPanel(); jpAccount.add(new JLabel("帐号")); JTextField userTextField = new JTextField(15); jpAccount.add(userTextField); jpAccount.add(new JLabel("用户注册")); jp.add(jpAccount); JPanel jpPass = new JPanel(); jpPass.add(new JLabel("密码")); JPasswordField passTextField = new JPasswordField(15); jpPass.add(passTextField); jpPass.add(new JLabel("找回密码")); jp.add(jpPass);

java Swing 登陆界面 为什么提示我空指针 求告诉..

1、你的sql语句写的不对,应该是 String sql = "select * from t_kq_user where name = ’"+i+"’ and password=’"+j+"’";2、PreparedStatement主要用于批量查询,你目前的情况用 Statement stmt=conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery(sql); if(rs.next()) …… 就可以了3、如果你确定空指针错误是这段代码的话,那么只可能是sql语句的错误了最好给 jPasswordField1.getText() 和 jTextField1.getText();加上判断不为空的条件,再.trim();

用swing,怎么样点击文件→登录,弹出一个登录框,可以输入用户名和密码,点击登录,用java怎么样实现

我上传一段代码,你看看能看懂不package com.iotek.stuManager.view;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JLabel;import java.awt.EventQueue;import java.awt.Font;import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.List;import javax.swing.JTextField;import javax.swing.JButton;import javax.swing.JPasswordField;import javax.swing.SwingConstants;/*** 登陆界面类* @author Bernard**/@SuppressWarnings("serial")public class FirstLogin extends JFrame {private JPanel contentPane;//容器private JTextField usernameInput;//文本框private JPasswordField pwdInput;//密码框private JLabel warning;//提示文本 private List《User》 users = new ArrayList《User》();// 创建用户集合/*** 程序主方法 启动第一个界面* Launch the application* @param args*/public static void main(String args) { //创建UI线程,EventQueue.invokeLater(new Runnable() {public void run() {try {//创建登陆界面FirstLogin window = new FirstLogin(); //窗口属性设置window.setResizable(false);//设置大小可变window.setVisible(true);//让窗口显示 } catch (Exception e) {e.printStackTrace();}}});}/*** 构造方法* 构造方法中初始化登陆界面内容*/public FirstLogin() {//初始化用户users.add(new User("admin", "admin")); //用户名 admin 密码 adminusers.add(new User("admin1", "admin1"));//用户名 admin1 密码 admin1users.add(new User("admin2", "admin2"));//用户名 admin2 密码 admin2users.add(new User("admin3", "admin3"));//用户名 admin3 密码 admin3users.add(new User("admin4", "admin4"));//用户名 admin4 密码 admin4users.add(new User("admin5", "admin5"));//用户名 admin5 密码 admin5/** 设置叉叉按钮功能*/setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 450, 300);//界面长宽高contentPane = new JPanel();//创建容器contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));//容器边界setContentPane(contentPane);//添加容器到主界面contentPane.setLayout(null);//设置布局为绝对布局/**初始化提示框*/warning = new JLabel("");//构造提示框warning.setHorizontalAlignment(SwingConstants.CENTER);//提示框风格warning.setBounds(105, 229, 239, 23);//提示框尺寸warning.setForeground(Color.red);//文本颜色contentPane.add(warning);//添加提示框到容器/** 标题栏*/JLabel title = new JLabel("用户管理系统");//构造标题栏title.setForeground(Color.BLUE);//设置字体颜色title.setFont(new Font("微软雅黑", Font.PLAIN, 24));//字体title.setBounds(152, 10, 292, 41);//设置大小contentPane.add(title);//添加标题到容器/** 版本栏*/JLabel version = new JLabel("version : V1.0");//初始化版本栏version.setBounds(42, 61, 97, 15);//设置版本栏位置contentPane.add(version);//添加版本栏到容器/** 用户名栏*/JLabel username = new JLabel("用户名:");//初始化用户名栏username.setBounds(72, 105, 63, 26);//设置大小contentPane.add(username);//添加到容器/** 密码栏*/JLabel pwd = new JLabel("密码 :");//初始化密码栏pwd.setBounds(72, 141, 63, 26);//设置大小contentPane.add(pwd);// 添加到容器/** 用户名输入栏*/usernameInput = new JTextField();//初始化用户名输入usernameInput.setBounds(187, 107, 177, 23);// 设置位置大小contentPane.add(usernameInput);// 添加到容器usernameInput.setColumns(10);// 限制长度 /** 登录按钮*/ JButton enter = new JButton("登录");//按钮初始化enter.setBounds(42, 189, 93, 23);//设置大小/*** 注册监听*/enter.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) { String inputUserName = usernameInput.getText();//取用户名char inputPwd = pwdInput.getPassword();// 取密码String pwd = String.valueOf(inputPwd);//字符数组转字符串 int value = checkusername(inputUserName, pwd);switch(value){case 1:FirstLogin.this.warning.setText("用户名或密码长度超出");break;case 2:FirstLogin.this.warning.setText("用户名或密码不能为空");break;case 3:EventQueue.invokeLater(new Runnable() {public void run() {try {new Success();} catch (Exception e) {e.printStackTrace();}}});FirstLogin.this.dispose();break;case 4:FirstLogin.this.warning.setText("密码错误");break;case 5:FirstLogin.this.warning.setText("用户不存在");break;}}});contentPane.add(enter);//添加按钮到容器/** 退出按钮*/JButton exit = new JButton("退出");// 构造清空按钮exit.setBounds(297, 189, 93, 23);// 位置大小/*** 注册监听*/exit.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {FirstLogin.this.dispose();}});contentPane.add(exit);/** 清空按钮*/JButton clear = new JButton("清空");//构造clear.setBounds(168, 189, 93, 23);//位置大小/*** 注册监听*/clear.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent arg0) {usernameInput.setText("");//清空用户名pwdInput.setText("");// 清空密码warning.setText("");// 清空警告}});contentPane.add(clear);/** 密码输入栏*/pwdInput = new JPasswordField();// 创建密码输入栏pwdInput.setBounds(187, 144, 177, 23);// 位置大小contentPane.add(pwdInput);// 添加到容器} /*** 检测用户名密码* @param userName 用户名* @param pwd 密码* @return 1.长度超出 2长度为零 3 验证失败 4验证成功 5未知错误*/private int checkusername(String userName,String pwd){if(userName.length()》11||pwd.length()》20){return 1;}if(userName.length()==0||pwd.length()==0){return 2;}for(User u : users){if(u.checkUserNmae(userName)){if(u.checkPwd(pwd)){return 3;}else{return 4;}}}return 5;//if(){//return 3;//}else if(value == 2){//return 4;//}else {//return 5;//}}/*** 内部内,用户类* @author Bernard**/class User{private String userName;// 用户名属性private String pwd;// 密码属性 public User(String userName ,String pwd) {this.userName = userName;this.pwd = pwd;} /*** 验证用户名* @param username* @return*/public boolean checkUserNmae(String username){if(this.userName.equals(username)){return true;}return false;} /*** 验证密码* @param pwd* @return*/public boolean checkPwd(String pwd){if(this.pwd.equals(pwd)){return true;}return false;} } /*** 内部类 登录成功界面类* @author Bernard**/class Success extends JFrame{ /*** 构造方法,构造成功后直接显示*/public Success() {setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 450, 300);//界面长宽高contentPane = new JPanel();//创建容器contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));//容器边界setContentPane(contentPane);//添加容器到主界面contentPane.setLayout(null);//设置布局为绝对布局 JLabel title = new JLabel("恭喜登录成功");//构造标题栏title.setForeground(Color.BLUE);//设置字体颜色title.setFont(new Font("微软雅黑", Font.PLAIN, 24));//字体title.setBounds(152, 50, 292, 41);//设置大小contentPane.add(title);//添加标题到容器this.setResizable(false); this.setVisible(true);}}}复制下来键个类直接可以运行的.这里面有你要的一切知识,看懂的话稍加修改就行

java swing做的登陆界面,怎样判断数据库中

1.写一个操作数据库的通用DAO(假设为Dao.java),提供·加载数据库驱动和获取数据库连接的方法:voidgetConnection();·执行查询的方法:ResultSetexecuteQuery(Stringsql);·执行更新的方法:IntegerexecuteUpdate(Stringsql);·关闭资源的方法:voidreleaseResource(Connectioncon);2.在你的界面中把用户名和密码取出来·username=yourTextField.getText();·password=yourPasswordField.getText();3.匹配·验证username、password是否是有效输入值(例如:不能包含特殊字符,不能有注入嫌疑等)·Stringsql="select*fromyourTablewhereusername=’"+username+"’andpassword=’"+password+"’";·Dao.executeQuery(sql):如果有结果说明合法,否则不合法。不懂Connect我

JAVA 用代码实现登入QQ空间操作

辽主临轩的分享分享java程序模拟qq登录界面的代码 java程序如何实现登录、记住密码、自动登录等功能!package dyno.swing.beans.qq;import javax.swing.*;import javax.swing.event.MouseInputListener;import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;/*import org.jvnet.substance.skin.SubstanceModerateLookAndFeel;import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;*/import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.io.IOException;import java.io.PrintWriter;import java.net.Socket;import java.net.UnknownHostException;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Scanner;public class QQLogin extends JFrame implements MouseInputListener,ActionListener{JLabel guanggao,beijing,wenzi,shezhi,zhanghaowb,qq1,dengluzhuangtai;// JTextField zhanghao;JPopupMenu haoma;JComboBox zhanghao;JPasswordField mima;JCheckBox jizhumima,zidongdenglu;JButton denglu,chashamuma;JProgressBar jpb;SimThread activity;Timer activityMonitor;String name,qq;Socket s;public QQLogin(){try {UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");} catch (ClassNotFoundException e1) {// TODO 自动生成 catch 块e1.printStackTrace();} catch (InstantiationException e1) {// TODO 自动生成 catch 块e1.printStackTrace();} catch (IllegalAccessException e1) {// TODO 自动生成 catch 块e1.printStackTrace();} catch (UnsupportedLookAndFeelException e1) {// TODO 自动生成 catch 块e1.printStackTrace();}chashamuma = new JButton("查杀木马");chashamuma.setBounds(240, 155,85, 20);this.add(chashamuma);jpb = new JProgressBar();jpb.setStringPainted(true);jpb.setBounds(100, 240, 200, 15);this.add(jpb);chashamuma.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){jpb.setMaximum(1000);//设置进度栏的最大值activity=new SimThread(1000);activity.start();//启动线程activityMonitor.start();//启动定时器chashamuma.setEnabled(false);//禁止按钮}});activityMonitor=new Timer(100,new ActionListener(){//每0.5秒执行一次public void actionPerformed(ActionEvent e){//以下动作将在事件调度线程中运行,十分安全int current=activity.getCurrent();//得到线程的当前进度jpb.setValue(current);//更新进度栏的值if(current==activity.getTarget()){//如果到达目标值activityMonitor.stop();//终止定时器chashamuma.setEnabled(true);//激活按钮} }});dengluzhuangtai = new JLabel(new ImageIcon("zaixianzhuangtai.jpg"));dengluzhuangtai.setBounds(75, 145, 35, 30);this.add(dengluzhuangtai);dengluzhuangtai.addMouseListener(this);denglu = new JButton("登录");denglu.setBounds(140, 155, 80, 20);this.add(denglu);this.setAlwaysOnTop(true);zidongdenglu = new JCheckBox("自动登录");zidongdenglu.setBounds(200, 190, 100, 30);this.add(zidongdenglu);jizhumima = new JCheckBox("记住密码");jizhumima.setBounds(100, 190, 100, 30);// jizhumima.setBackground(new Color(228, 244, 255));this.add(jizhumima);haoma = new JPopupMenu();/* zhanghao = new JTextField(20);zhanghao.setBounds(120, 78, 135, 20);zhanghao.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.WHITE));zhanghao.setFont(new Font("宋体",Font.PLAIN,13));this.add(zhanghao);*/// zhanghaowb = new JLabel(new ImageIcon("2.png"));// zhanghaowb.setBounds(90, 73, 194, 31);// jiantou = new JLabel(new ImageIcon("baijiantou.png"));// jiantou.setBounds(256, 78, 23, 21);// jiantou.addMouseListener(this);// this.add(jiantou);// this.add(zhanghaowb);chashamuma.addActionListener(this);mima = new JPasswordField();mima.setEchoChar(’*’);mima.setFont(new Font("宋体",Font.PLAIN,13));mima.setBounds(100, 113, 150, 20);this.add(mima);zhanghao = new JComboBox();zhanghao.setEditable(true);zhanghao.setBounds(100, 78, 150, 20);zhanghao.setFont(new Font("宋体",Font.PLAIN,13));this.add(zhanghao);guanggao = new JLabel(new ImageIcon("guanggao.gif"));guanggao.setBounds(0, 0, 334, 64);beijing = new JLabel(new ImageIcon("beijing.jpg"));beijing.setBounds(0, 64, 334, 154);wenzi = new JLabel(new ImageIcon("wenzi.jpg"));wenzi.setBounds(30, 75, 50, 100);denglu.addActionListener(this);// zhanghaowb.addMouseListener(this);// zhanghao.addMouseListener(this);this.add(wenzi);this.add(beijing);this.setLayout(null);this.add(guanggao);this.setVisible(true);this.setDefaultCloseOperation(3);this.setSize(340, 250);this.setLocationRelativeTo(null);}public static void main(String args) {/*JFrame.setDefaultLookAndFeelDecorated(true);try {UIManager.setLookAndFeel(new SubstanceOfficeBlue2007LookAndFeel()) ;UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel"); } catch (Exception e) {System.out.println("Substance Raven Graphite failed to initialize");}SwingUtilities.invokeLater(new Runnable() {public void run() {QQLogin w = new QQLogin();w.setVisible(true);}});*/new QQLogin();}public void mouseClicked(MouseEvent e) {// TODO 自动生成方法存根}public void mouseEntered(MouseEvent e) {if(e.getSource() == dengluzhuangtai){dengluzhuangtai.setIcon(new ImageIcon("zaixianzhuangtaidian.jpg"));}}public void mouseExited(MouseEvent e) {if(e.getSource() == dengluzhuangtai){dengluzhuangtai.setIcon(new ImageIcon("zaixianzhuangtai.jpg"));}}public void mousePressed(MouseEvent e) {// TODO 自动生成方法存根}public void mouseReleased(MouseEvent e) {// TODO 自动生成方法存根}public void mouseDragged(MouseEvent e) {// TODO 自动生成方法存根}public void mouseMoved(MouseEvent e) {// TODO 自动生成方法存根}public class liaotianchuangkou{}class SimThread extends Thread{//线程类private int current;//进度栏的当前值private int target;//进度栏的最大值public SimThread(int t){current=0;target=t;}public int getTarget(){return target;}public int getCurrent(){return current;}public void run(){//线程体try{while (current《target && !interrupted()){//如果进度栏的当前值小于目标值并且线程没有被中断sleep(10);current++;if(current == 700){sleep(3000);}else if(current == 730){sleep(1000);}}}catch (InterruptedException e){}}}public void actionPerformed(ActionEvent e) {if(e.getSource() == chashamuma){this.setBounds(300, 300, 340, 300);}else if(e.getSource() == denglu){String zh = (String) zhanghao.getSelectedItem();System.out.println(zhanghao.getSelectedItem());// System.out.println(zhanghao.getItemAt(0));char str = mima.getPassword();String mima = String.valueOf(str);;System.out.println(mima);// Sql login = new Sql();// if(login.login(zh,mima))// {try {s = new Socket("127.0.0.1",8888);System.out.println(s);PrintWriter pw;Scanner sc;pw = new PrintWriter(s.getOutputStream(),true);sc = new Scanner(s.getInputStream());String str2 = "login#289872400198724#"+zh+"#289872400198724#"+mima;System.out.println(str2);pw.println(str2);String str3 = sc.nextLine();String yanzheng = str3.split("#");System.out.println(str3);if(yanzheng.equals("true")){System.out.println("登陆成功!");name = yanzheng;qq = yanzheng;// this.setVisible(false);// Thread.sleep(5000);System.out.println("woao"+name);System.out.println("woai"+qq);Logined logined = new Logined(name,qq);this.setVisible(false);}else{JOptionPane.showMessageDialog(this, "用户名或密码错误!", "用户名或密码错误!", 0);}} catch (UnknownHostException e2) {// TODO 自动生成 catch 块e2.printStackTrace();} catch (IOException e2) {// TODO 自动生成 catch 块e2.printStackTrace();} /*try {login.rs = login.stat.executeQuery("select * from qquser where username=’"+zh+"’ and password = ’"+mima+"’");boolean flag = login.rs.next();if(flag == true){name = login.rs.getString("name");qq = login.rs.getString("username");}else{}*/// } catch (SQLException e1) {// TODO 自动生成 catch 块// e1.printStackTrace();// }}else{JOptionPane.showMessageDialog(this, "用户名或密码错误", "输入错误", 0);}// this.setVisible(false);//new Logined();}}

以上就是我们为大家找到的有关“自动登录javaswing(SWT做出像QQ那种的保存密码和自动登录的功能)”的所有内容了,希望可以帮助到你。如果对我们网站的其他内容感兴趣请持续关注本站。