導航:首頁 > 編程語言 > qq登錄用戶頁面設計java

qq登錄用戶頁面設計java

發布時間:2023-05-28 12:44:14

1. 用java能做qq界面嗎

java實現簡單QQ登陸界面:
1.生成界面的java代碼
packageQQ2014;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclassQQ2014{
//創建登陸界面類
publicvoidshowLoginFrame(){
//創建船體對象
JFrameloginFrame=newJFrame();
//設置大小,位置,標題
loginFrame.setSize(300,200);
loginFrame.setTitle("QQ2014");
loginFrame.setLocationRelativeTo(null);
//創建流式分布對象
FlowLayoutlayout=newFlowLayout();
loginFrame.setLayout(layout);
//創建賬戶名,密碼和輸入框
JLabeluser_name=newJLabel("賬號:");
JLabeluser_password=newJLabel("密碼:");
JTextFieldfield_name=newJTextField(20);
JPasswordFieldfield_password=newJPasswordField(20);
//創建登陸,重置按鈕
JButtonbutton_reset=newJButton("重置");
JButtonbutton_login=newJButton("登陸");
//設置窗體可見
loginFrame.setVisible(true);
//創建事件監聽對象
ActionListeneraction_listener1=newActionListener(){
publicvoidactionPerformed(ActionEvente){
Stringname=field_name.getText();
Stringpassword=field_password.getText();
if("zhaoxin".equals(name)&&"123".equals(password))
{
showIndexFrame();
loginFrame.setDefaultCloseOperation(3);
loginFrame.setVisible(false);
}
else{
System.out.println("密碼錯誤,重新輸入!");
}
}
};
ActionListeneraction_listener2=newActionListener(){
publicvoidactionPerformed(ActionEvente){
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);
}
publicvoidshowIndexFrame(){
//創建窗體對象
JFrameindexFrame=newJFrame();
indexFrame.setSize(200,500);
indexFrame.setTitle("QQ好友列表");
indexFrame.setLocationRelativeTo(null);
//設置流式分布對象
FlowLayoutlayout=newFlowLayout(FlowLayout.CENTER,100,10);
indexFrame.setLayout(layout);
//創建好友按鈕
for(inti=0;i<10;i++)
{
JButtonbutton_friend=newJButton("friend"+i);
//創建動作事件監聽對象
ActionListeneraction_listener=newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
showChatFrame();
indexFrame.setVisible(false);
indexFrame.setDefaultCloseOperation(3);
}
};
button_friend.addActionListener(action_listener);
indexFrame.add(button_friend);
}
//設置窗體可見
indexFrame.setVisible(true);
}
publicvoidshowChatFrame(){
//創建窗體,大小,位置,標題
JFramechatFrame=newJFrame();
chatFrame.setSize(400,400);
chatFrame.setTitle("正在聊天中...");
chatFrame.setLocationRelativeTo(null);
//創建聊天記錄,輸入域
JTextAreaarea_input=newJTextArea(10,30);
JTextAreaarea_record=newJTextArea(5,30);
//創建流式分布對象
FlowLayoutlayout=newFlowLayout(FlowLayout.CENTER,0,10);
chatFrame.setLayout(layout);
//創建發送,關閉按扭
JButtonbutton_send=newJButton("發送");
JButtonbutton_close=newJButton("關閉");
//創建動作事件監聽對象
ActionListeneraction_listener1=newActionListener()
{
publicvoidactionPerformed(ActionEvente){
area_record.setText(area_record.getText()+" "+area_input.getText());
area_input.setText("");
}
};
ActionListeneraction_listener2=newActionListener()
{
publicvoidactionPerformed(ActionEvente){
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.javamain方法調用
packageQQ2014;
publicclassTest{
publicstaticvoidmain(String[]args){
QQ2014qq=newQQ2014();
qq.showLoginFrame();
}
}

來自博客 小梁123 的分享

2. 用java製作qq登錄界面,只要界面,不要事件處理

package 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);

//登錄設置
JPanel jpstatus = new JPanel();
jpstatus.add(new JLabel("狀態"));
JComboBox statusComboBox = new JComboBox();
statusComboBox.addItem("Q我");
statusComboBox.addItem("在線");
statusComboBox.addItem("隱身");
statusComboBox.addItem("離線");
jpstatus.add(statusComboBox);
jpstatus.add(new JCheckBox("記住密碼"));
jpstatus.add(new JCheckBox("自動登錄"));
jp.add(jpstatus);
add(jp);

//底部登錄按鈕
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BorderLayout());
bottomPanel.add(new JButton("設置"),BorderLayout.WEST);
bottomPanel.add(new JButton("登錄"),BorderLayout.EAST);
add(bottomPanel,BorderLayout.SOUTH);
setSize(324,230);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}

/**
* @param args
*/
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable(){

@Override
public void run() {
new QQLoginView().setVisible(true);

}

});

}
}

3. 登錄界面,用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);

/**
* 實現系統托盤
*/
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();
}
}

4. java QQ登陸界面代碼

package com.demo4;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
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;
import javax.swing.border.EmptyBorder;

public class Demo1 extends JFrame{
public Demo1(){
init();
}
private void init(){
ImageIcon icon=new ImageIcon("Image/8.jpg");
setIconImage(icon.getImage());
setTitle("QQ2011");
setSize(310,270);
setContentPane(createContentPane());
}
private JPanel createContentPane(){
JPanel pane=new JPanel(new BorderLayout());
pane.add(BorderLayout.NORTH,new JLabel(new ImageIcon("Image/5.jpg")));
pane.add(BorderLayout.CENTER,createPane());
pane.add(BorderLayout.SOUTH,createButtonPane());
return pane;
}
private JPanel createPane(){
JPanel pane=new JPanel(new BorderLayout());
pane.setBorder(new EmptyBorder(12,24,12,24));
pane.add(BorderLayout.NORTH,createGridPane());
pane.add(BorderLayout.CENTER,createCheckBoxPane());
return pane;
}
private JPanel createGridPane(){
JPanel pane=new JPanel(new GridLayout(2,1,0,8));
pane.add(createName());
pane.add(createPassword());
return pane;
}
private JPanel createName(){
JPanel pane=new JPanel(new BorderLayout());
pane.add(BorderLayout.WEST,new JLabel("賬號"));
pane.add(BorderLayout.CENTER,new JTextField(10));
pane.add(BorderLayout.EAST,new JButton("清除賬號"));
return pane;
}
private JPanel createPassword(){
JPanel pane=new JPanel(new BorderLayout());
pane.add(BorderLayout.WEST,new JLabel("密碼"));
pane.add(BorderLayout.CENTER,new JPasswordField(10));
pane.add(BorderLayout.EAST,new JButton("忘記密碼"));
return pane;
}
private JPanel createCheckBoxPane(){
JPanel pane=new JPanel(new FlowLayout());
JCheckBox jcb1=new JCheckBox("隱身登陸");
JCheckBox jcb2=new JCheckBox("記住密碼");
pane.add(jcb1);
pane.add(jcb2);
return pane;
}
private JPanel createButtonPane(){
JPanel pane=new JPanel(new FlowLayout());
JButton denglu=new JButton("登陸");
JButton quxiao=new JButton("取消");
JComboBox jcbb=new JComboBox();
String[]jc={"上線","隱身","離線","忙碌"};
jcbb=new JComboBox(jc);
pane.add(denglu);
pane.add(quxiao);
pane.add(jcbb);
return pane;
}
public void ActionListener(){
for(int i=0;i<=i;i++)
System.out.println(i);
}

public void xianshi(){
setVisible(true);
}

}
下面是主函數的代碼 估計包可能還有問題 還有圖片的問題
package com.demo4;

public class Main1 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Demo1 a=new Demo1();
a.xianshi();
}

}

5. 用java怎麼實現QQ登錄界面

用java做QQ登錄界面的寫法如下:

package ch10;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

1、//定義該類繼承自,實現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;i<2;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();

}

}

6. 怎麼用JAVA編寫QQ的登陸界面

if(輸入的用戶名和密碼正確此困枝)
{
JOptionPane.showMessageDialog(JFrame,"登陸狀態","恭喜你登陸成功",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE);
}
else if(輸入的用戶名和密碼不正確)
{
JOptionPane.showMessageDialog(JFrame,"登陸尺好狀態","對不起森敏登陸失敗",JOptionPane.YES_OPTION,JOptionPane.ERROR_MESSAGE);
}

7. 如何利用java、access製作一個QQ界面並實現登錄功能。。。

...........登錄功能本身,只要通過jdbc執行sql語句,進行查詢操作即可,至於前睜激QQ界面,最簡易的做法是,打開QQ客戶端做個截圖,然後通過jsp引用這個截圖,在用戶早旅名和密碼輸入框那裡,放上輸入域,在登錄那裡,放慧襪上submit按鈕即可,將這兩個元素用form括起來即可。

8. 用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;i<2;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();

}

}

9. 請問用java程序模擬qq登錄界面的代碼怎麼寫啊

太簡單了!你看看! package dyno.swing.beans.qq; import javax.swing.*; import javax.swing.event.MouseInputListener; import org.jvnet.substance.skin.; /*import org.jvnet.substance.skin.SubstanceModerateLookAndFeel; import org.jvnet.substance.skin.;*/ 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,she,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 ( 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("jiantou.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.(true); try { UIManager.setLookAndFeel(new ()) ; UIManager.setLookAndFeel("org.jvnet.substance.skin."); } 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[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(); } }

閱讀全文

與qq登錄用戶頁面設計java相關的資料

熱點內容
彩視製作教程 瀏覽:766
聖墟在哪個App看免費 瀏覽:395
網路哪些不能玩 瀏覽:868
probe315使用教程 瀏覽:646
數字電位器程序 瀏覽:198
c代碼整理 瀏覽:104
網路營銷具有什麼優勢 瀏覽:378
右下角網路連接不顯示寬頻連接 瀏覽:940
ps修改tif文件 瀏覽:580
預防醫學如何轉行做大數據 瀏覽:234
pdf文件變藍 瀏覽:309
怎麼在pdf文件上面用k寶簽名 瀏覽:213
如何知道表格里數據後面有空格 瀏覽:720
gee引擎更新系統找不到指定文件 瀏覽:802
貝殼網的數據刪除了如何找回 瀏覽:509
華為榮耀6x怎麼切換網路 瀏覽:418
手機里的pdf文件在哪放 瀏覽:889
java版貪吃蛇畢業論文 瀏覽:989
微信公共號郵箱 瀏覽:415
圖片寬度代碼 瀏覽:460

友情鏈接