qq登陆框java代码 登录界面java代码

登录界面,用Java做 , 类似于QQ的,要求有用户名,密码,以及登录按钮,当登陆成功时,提示登陆成功!主要代码
/**
* 登录面板
*/
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login{
private TrayIcon trayIcon;//托盘图标
private SystemTray systemTray;//系统托盘
public Login() {
final JFrame myJFrame = new JFrame(" 登录");
myJFrame.setBounds(520, 200, 300, 250);
myJFrame.setLayout(new BorderLayout());
myJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
【qq登陆框java代码 登录界面java代码】/**
* 实现系统托盘
*/
systemTray = SystemTray.getSystemTray();//获得系统托盘的实例
try {
trayIcon = new TrayIcon(ImageIO.read(new File("o.gif")));
systemTray.add(trayIcon);//设置托盘的图标,0.gif与该类文件同一目录
}
catch (IOException e1) {e1.printStackTrace();}
catch (AWTException e2) {e2.printStackTrace();}
myJFrame.addWindowListener(
new WindowAdapter(){
public void windowIconified(WindowEvent e){
myJFrame.dispose();//窗口最小化时dispose该窗口
}
});
trayIcon.addMouseListener(
new MouseAdapter(){
public void mouseClicked(MouseEvent e){
if(e.getClickCount() == 2)//双击托盘窗口再现
{
myJFrame.setExtendedState(Frame.NORMAL);
myJFrame.setVisible(true);
}
if(e.getClickCount() == 1)
trayIcon.displayMessage("李", "", TrayIcon.MessageType.INFO);
}
public void mouseEntered(MouseEvent e){
trayIcon.displayMessage("a", "b", TrayIcon.MessageType.INFO);
}
});
//myJFrame.setIconImage(Toolkit.getDefaultToolkit().createImage(JFrame.class.getResource("images/topLogin.jpg")));
//显示图像
JLabel topLoginJLabel = new JLabel(new ImageIcon("images/topLogin.jpg"));
JPanel topJPanel = new JPanel();
topJPanel.add(topLoginJLabel);
topJPanel.setBackground(Color.black);
myJFrame.add(topJPanel, BorderLayout.NORTH);
final JPanel myJPanel = new JPanel();
myJFrame.setResizable(false);
JLabel myJLabel1 = new JLabel("用户名:");
JLabel myJLabel2 = new JLabel("密码:");
JLabel myJLabel3 = new JLabel("验证码:");
final JTextField myJTextField1 = new JTextField();
final JPasswordField myJPasswordField1 = new JPasswordField();
final JTextField myJTextField3 = new JTextField();
//按钮
JButton myJButton1 = new JButton("确认");
JButton myJButton2 = new JButton("重置");
JButton myJButton3 = new JButton("注册");
//背景色
myJPanel.setBackground(Color.getHSBColor(212, 223, 23));
//设置面板布局
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
myJPanel.setLayout(gridbag);
MyLayout myLay = new MyLayout();
myLay.buildConstraints(constraints, 0, 0, 1, 1, 20, 35);
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(myJLabel1, constraints);
myLay.buildConstraints(constraints, 1, 0, 1, 1, 80, 0);
constraints.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(myJTextField1, constraints);
myLay.buildConstraints(constraints, 0, 1, 1, 1, 0, 25);
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(myJLabel2, constraints);
myLay.buildConstraints(constraints, 1, 1, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(myJPasswordField1, constraints);
myLay.buildConstraints(constraints, 0, 2, 1, 1, 33, 25);
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(myJLabel3, constraints);
myLay.buildConstraints(constraints, 1, 2, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(myJTextField3, constraints);
myLay.buildConstraints(constraints, 2, 2, 1, 1, 34, 0);
constraints.fill = GridBagConstraints.HORIZONTAL;
@SuppressWarnings("unused")
JudgeCode myJudgeCode = new JudgeCode();
gridbag.setConstraints(JudgeCode.judgeCodeLabel, constraints);//验证码
myLay.buildConstraints(constraints, 0, 3, 1, 1, 33, 15);
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(myJButton1, constraints);
myLay.buildConstraints(constraints, 1, 3, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.CENTER;
gridbag.setConstraints(myJButton2, constraints);
myLay.buildConstraints(constraints, 2, 3, 1, 1, 34, 0);
constraints.fill = GridBagConstraints.NONE;
gridbag.setConstraints(myJButton3, constraints);
myJPanel.add(myJLabel1);
myJPanel.add(myJTextField1);
myJPanel.add(myJLabel2);
myJPanel.add(myJPasswordField1);
myJPanel.add(myJLabel3);
myJPanel.add(myJTextField3);
myJPanel.add(JudgeCode.judgeCodeLabel);
myJPanel.add(myJButton1);
myJPanel.add(myJButton2);
myJPanel.add(myJButton3);
myJFrame.add(myJPanel, BorderLayout.CENTER);
//确认单击事件
myJButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String username = new String(myJTextField1.getText()); //用户名
String mypassword = new String(myJPasswordField1.getPassword()); //获取密码
/**
* 数据库操作
*/
DataConn dataconn = new DataConn();
String sql = "select * from user_information where name = '" username "'";
dataconn.executeQuery(sql);
try {
if(username == null || username == "" || mypassword == null || mypassword == "" || myJTextField3.getText() == null || myJTextField3.getText() == ""){
JOptionPane.showMessageDialog(null, "用户名、密码、验证码不能为空!请重新输入!");
}
else if(!dataconn.rs.next()){
JOptionPane.showMessageDialog(null, "你输入的用户名不存在!请重新输入!");
myJTextField1.setText("");
myJPasswordField1.setText("");
}
else if(!dataconn.rs.getString("password").equals(mypassword))
{
JOptionPane.showMessageDialog(null, "你输入的密码错误!请重新输入!");
myJPasswordField1.setText("");
}
else if(!myJTextField3.getText().equals(JudgeCode.code)){
JOptionPane.showMessageDialog(null, "你输入的验证码错误!请重新输入!");
}
else
{
JOptionPane.showMessageDialog(null, "登录成功!");
@SuppressWarnings("unused")
Index myIndex = new Index();//进入程序主界面
myJFrame.setVisible(false);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dataconn.closeStmt();
dataconn.closeConn();
}
});
//重置的单击事件
myJButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
myJTextField1.setText("");
myJPasswordField1.setText("");
}
});
//注册
myJButton3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
@SuppressWarnings("unused")
Register myRegister = new Register();
}
});
myJFrame.setVisible(true);//需要放在后面,不然得刷新才能显示页面
}
public static void main(String []args){
@SuppressWarnings("unused")
Login myLogin = new Login();
}
}
怎么用java打开qqjava实现简单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();
}
}
求QQ登陆界面的Java GUI(图形用户界面开发)代码!import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
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;
public class Demo extends JFrame{
Container contentPane;
ImageIcon img = new ImageIcon("002.jpg");
JPanel paneTop = new JPanel();
JPanel paneMid = new JPanel();
JPanel paneBut = new JPanel();
JPanel paneAll = new JPanel();
JLabel lblTop = new JLabel();
JLabel lblName = new JLabel();
JLabel lblPwd = new JLabel();
JLabel lblApply = new JLabel();
JLabel lblForget = new JLabel();
JLabel lblModel = new JLabel();
JLabel lblNull = new JLabel();
JTextField txtName = new JTextField(15);
JPasswordField txtPwd = new JPasswordField(15);
JComboBox cmb = new JComboBox();
JCheckBox chk = new JCheckBox();
JButton btnKill = new JButton("查杀木马");
JButton btnSet = new JButton("设置");
JButton btnLogin = new JButton("登录");
Demo(){
lblTop.setIcon(img);
paneTop.add(lblTop);
lblName.setText("QQ帐号:");
lblApply.setText("申请帐号");
lblPwd.setText("QQ密码:");
lblForget.setText("忘记密码?");
lblModel.setText("状态:");
String[] s1 = {"隐身","在线","忙碌"};
cmb.addItem(s1[0]);
cmb.addItem(s1[1]);
cmb.addItem(s1[2]);
chk.setText("自动登录");
paneMid.add(lblName);
paneMid.add(txtName);
paneMid.add(lblApply);
paneMid.add(lblPwd);
paneMid.add(txtPwd);
paneMid.add(lblForget);
paneMid.add(lblModel);
paneMid.add(cmb);
paneMid.add(chk);
paneBut.add(btnKill);
paneBut.add(btnSet);
paneBut.add(btnLogin);
contentPane = this.getContentPane();
contentPane.add(paneTop,BorderLayout.NORTH);
contentPane.add(paneMid,BorderLayout.CENTER);
contentPane.add(paneBut,BorderLayout.SOUTH);
setTitle("欢迎使用QQ");
setSize(330,240);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screen.width - getSize().width)/2,(screen.height - getSize().height)/2 );
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
Demo d = new Demo();
}
}
怎么用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登录界面是javeSE 。主要用来编写一些界面程序 , 带窗口的 。
ME是专门用来手机开发的 。不过前途不咋滴了 。
EE是用来进行企业级开发的 。多少是BS编程,就是网站类程序 。
这3个的基本的java基础类都是一样 的 。
区别是:
SE含有SWing等界面类 。
ME有很多对手机硬件操作的类 。
EE有很多WEB开发的类 。
希望对你有所帮助!o(∩_∩)o 哈哈
用java怎么实现QQ登录界面?用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=0;i2;i)
{
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();
}
}
qq登陆框java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于登录界面java代码、qq登陆框java代码的信息别忘了在本站进行查找喔 。

    推荐阅读