用java怎么实现QQ登录界面?

Python017

用java怎么实现QQ登录界面?,第1张

用java做QQ登录界面的写法如下:

package ch10

import java.awt.*

import java.awt.event.*

import javax.swing.*

1、//定义该类继承自JFrame,实现ActionListener接口

public class LoginTest extends JFrame implements ActionListener

{

2、//创建JPanel对象

private JPanel jp=new JPanel()

3、//创建3个标并加入数组

JLabel name = new JLabel("请输入用户名")

JLabel password = new JLabel("请输入密码")

JLabel show = new JLabel("")

private JLabel[] jl={name,password,show}

4、//创建登陆和重置按扭并加入数组

JButton login = new JButton("登陆")

JButton reset = new JButton("重置")

private JButton[] jb={login,reset}

5、//创建文本框以及密码框

private JTextField jName=new JTextField()

private JPasswordField jPassword =new JPasswordField()

public LoginTest()

{

6、//设置布局管理器为空布局,这里自己摆放按钮、标签和文本框

jp.setLayout(null)

for(int i=0i<2i++)

{

7、//设置标签和按扭的位置与大小

jl[i].setBounds(30,20+40*i,180,20)

jb[i].setBounds(30+110*i,100,80,20)

8、//添加标签和按扭到JPanel容器中

jp.add(jl[i])

jp.add(jb[i])

//为2个按钮注册动作事件监听器

jb[i].addActionListener(this)

}

9、//设置文本框的位置和大小,注意满足美观并足够用户名的长度

jName.setBounds(130,15,100,20)

10、//添加文本框到JPanel容器中

jp.add(jName)

11、//为文本框注册动作事件监听器

jName.addActionListener(this)

12、//设置密码框的位置和大小,注意满足美观和足够密码的长度

jPassword.setBounds(130,60,100,20)

13、//添加密码框到JPanel容器中

jp.add(jPassword)

14、//设置密码框中的回显字符,这里设置美元符号

jPassword.setEchoChar('$')

15、//为密码框注册动作事件监听器

jPassword.addActionListener(this)

16、//设置用于显示登陆状态的标签大小位置,并将其添加进JPanel容器

jl[2].setBounds(10,180,270,20)

jp.add(jl[2])

17、//添加JPanel容器到窗体

this.add(jp)

18、//设置窗体的标题、位置、大小、可见性及关闭动作

this.setTitle("登陆窗口")

this.setBounds(200,200,270,250)

this.setVisible(true)

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

}

19、//实现动作监听器接口中的方法actionPerformed

public void actionPerformed(ActionEvent e)

{

20、//如果事件源为文本框

if(e.getSource()==jName)

{

21、//切换输入焦点到密码框

jPassword.requestFocus()

}

22、//如果事件源为重置按扭

else if(e.getSource()==jb[1])

{

23、//清空姓名文本框、密码框和show标签中的所有信息

jl[2].setText("")

jName.setText("")

jPassword.setText("")

24、//让输入焦点回到文本框

jName.requestFocus()

}

25、//如果事件源为登陆按钮,则判断登录名和密码是否正确

else

{

26、//判断用户名和密码是否匹配

if(jName.getText().equals("lixiangguo")&&

String.valueOf(jPassword.getPassword()).equals("19801001"))

{

27、jl[2].setText("登陆成功,欢迎您的到来!")

}

else

{

28、jl[2].setText("对不起,您的用户名或密码错误!")

}

}

}

public static void main(String[] args)

{

29、//创建LoginTest窗体对象

new LoginTest()

}

}

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=0i<10i++)

{

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()

}

}

很有可能是手机QQ记录你登陆信息的文件损坏,或者丢失,(类似IE的cookie)。任何程序的登陆机制都是获取用户名和密码,然后到服务器存储用户信息的数据库中去比对实现的。你登自己的QQ不行,而登别人的QQ可以,就是说明,你的QQ和服务器的交互是没有问题的,唯一可能的原因就是你使用了“自动登录”功能,而手机中存储你登陆信息的文件又有问题。解决方案:1.去除自动登录,手动输入QQ号和密码2.如果不行,建议重启手机3.如果还不行,重装QQ希望可以帮到你