当前位置:首页 > 代码 > 正文

java简单的qq登陆界面代码(java实现登录)

admin 发布:2022-12-19 03:51 91


今天给各位分享java简单的qq登陆界面代码的知识,其中也会对java实现登录进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

怎么用java打开qq

java实现简单QQ登陆界面:

1.生成界面的java代码

package QQ2014;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class QQ2014 {

//创建登陆界面类

public void showLoginFrame(){

//创建船体对象

JFrame loginFrame=new JFrame();

//设置大小,位置,标题

loginFrame.setSize(300,200);

loginFrame.setTitle("QQ2014");

loginFrame.setLocationRelativeTo(null);

//创建流式分布对象

FlowLayout layout=new FlowLayout();

loginFrame.setLayout(layout);

//创建账户名,密码和输入框

JLabel user_name=new JLabel("账号:");

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

JTextField field_name=new JTextField(20);

JPasswordField field_password=new JPasswordField(20);

//创建登陆,重置按钮

JButton button_reset=new JButton("重置");

JButton button_login=new JButton("登陆");

//设置窗体可见

loginFrame.setVisible(true);

//创建事件监听对象

ActionListener action_listener1=new ActionListener(){

public void actionPerformed(ActionEvent e){

String name=field_name.getText();

String password=field_password.getText();

if("zhaoxin".equals(name)"123".equals(password))

{

showIndexFrame();

loginFrame.setDefaultCloseOperation(3);

loginFrame.setVisible(false);

}

else{

System.out.println("密码错误,重新输入!");

}

}

};

ActionListener action_listener2=new ActionListener(){

public void actionPerformed(ActionEvent e){

field_name.setText("");

field_password.setText("");

}

};

//将文本输入框,按钮,事件监听对象添加

loginFrame.add(user_name);

loginFrame.add(field_name);

loginFrame.add(user_password);

loginFrame.add(field_password);

loginFrame.add(button_reset);

loginFrame.add(button_login);

button_reset.addActionListener(action_listener2);

button_login.addActionListener(action_listener1);

}

public void showIndexFrame(){

//创建窗体对象

JFrame indexFrame=new JFrame();

indexFrame.setSize(200,500);

indexFrame.setTitle("QQ好友列表");

indexFrame.setLocationRelativeTo(null);

//设置流式分布对象

FlowLayout layout=new FlowLayout(FlowLayout.CENTER,100,10);

indexFrame.setLayout(layout);

//创建好友按钮

for(int i=0;i10;i++)

{

JButton button_friend=new JButton("friend"+i);

//创建动作事件监听对象

ActionListener action_listener=new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

showChatFrame();

indexFrame.setVisible(false);

indexFrame.setDefaultCloseOperation(3);

}

};

button_friend.addActionListener(action_listener);

indexFrame.add(button_friend);

}

//设置窗体可见

indexFrame.setVisible(true);

}

public void showChatFrame(){

//创建窗体,大小,位置,标题

JFrame chatFrame=new JFrame();

chatFrame.setSize(400,400);

chatFrame.setTitle("正在聊天中...");

chatFrame.setLocationRelativeTo(null);

//创建聊天记录,输入域

JTextArea area_input=new JTextArea(10,30);

JTextArea area_record=new JTextArea(5,30);

//创建流式分布对象

FlowLayout layout=new FlowLayout(FlowLayout.CENTER,0,10);

chatFrame.setLayout(layout);

//创建发送,关闭按扭

JButton button_send=new JButton("发送");

JButton button_close=new JButton("关闭");

//创建动作事件监听对象

ActionListener action_listener1=new ActionListener()

{

public void actionPerformed(ActionEvent e){

area_record.setText(area_record.getText()+"\n"+area_input.getText());

area_input.setText("");

}

};

ActionListener action_listener2=new ActionListener()

{

public void actionPerformed(ActionEvent e){

chatFrame.setVisible(false);

chatFrame.setDefaultCloseOperation(3);

}

};

//设置窗体可见

chatFrame.setVisible(true);

//添加按钮,事件监听对象

chatFrame.add(area_record);

chatFrame.add(area_input);

chatFrame.add(button_send);

chatFrame.add(button_close);

button_send.addActionListener(action_listener1);

button_close.addActionListener(action_listener2);

}

}

复制代码

2.java main方法调用

package QQ2014;

public class Test {

public static void main(String[] args){

QQ2014 qq=new QQ2014();

qq.showLoginFrame();

}

}

怎么用JAVA编写QQ的登陆界面

if(输入的用户名和密码正确)

{

JOptionPane.showMessageDialog(JFrame,"登陆状态","恭喜你登陆成功",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE);

}

else if(输入的用户名和密码不正确)

{

JOptionPane.showMessageDialog(JFrame,"登陆状态","对不起登陆失败",JOptionPane.YES_OPTION,JOptionPane.ERROR_MESSAGE);

}

怎么用JAVA做QQ登陆界面的密码框

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class QQLogin extends JFrame {

JTextField jtf,jtf1;

public QQLogin() {

jtf = new JTextField(12);

jtf.setText("请输入");

jtf.setForeground(Color.GRAY);// 设置颜色

JPanel jp = new JPanel();

jp.add(jtf);

jtf1 = new JTextField(12);

JPanel jp1 = new JPanel();

jp1.add(jtf1);

this.add(jp1, BorderLayout.NORTH);

this.add(jp,BorderLayout.SOUTH);

this.setTitle("密码输入提示");

this.setBounds(300, 200, 220, 160);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

//jp1.getComponents()[0].setBackground(Color.RED);

//jp1上可能添加了很多组件,于是可以使用getComponents()返回一个组件数组。

//[0]表示选取该组件数组的第一个组件

//setBackground(Color.RED) 表示把该组件变成红色的背景颜色

jtf.addFocusListener(new FocusListener() {

@Override

public void focusLost(FocusEvent e) {// 失去焦点的时候

// 如果内容为空,设置文本

if (jtf.getText().trim().equals("")) {

jtf.setText("请输入");

}

}

@Override

public void focusGained(FocusEvent e) {// 得到焦点的时候

if (jtf.getText().trim().equals("请输入")) {

jtf.setText("");// 让文本为空白

}

}

});

}

public static void main(String[] args) {

new QQLogin();

}

}

代码上已经回答了你的2个问题

请问用java程序模拟qq登录界面的代码怎么写啊?

太简单了!你看看! 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 (currenttarget !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[0].equals("true")) { System.out.println("登陆成功!"); name = yanzheng[1]; qq = yanzheng[2]; // 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(); } }

java简单的qq登陆界面代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java实现登录、java简单的qq登陆界面代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/1951.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载