java實現(xiàn)簡單QQ登陸界面:

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設,硯山企業(yè)網(wǎng)站建設,硯山品牌網(wǎng)站建設,網(wǎng)站定制,硯山網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,硯山網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
1.生成界面的java代碼
package?QQ2014;
import?javax.swing.*;
import?java.awt.*;
import?java.awt.event.*;
public?class?QQ2014?{
//創(chuàng)建登陸界面類
public?void?showLoginFrame(){
//創(chuàng)建船體對象
JFrame?loginFrame=new?JFrame();
//設置大小,位置,標題
loginFrame.setSize(300,200);
loginFrame.setTitle("QQ2014");
loginFrame.setLocationRelativeTo(null);
//創(chuàng)建流式分布對象
FlowLayout?layout=new?FlowLayout();
loginFrame.setLayout(layout);
//創(chuàng)建賬戶名,密碼和輸入框
JLabel?user_name=new?JLabel("賬號:");
JLabel?user_password=new?JLabel("密碼:");
JTextField?field_name=new?JTextField(20);
JPasswordField?field_password=new?JPasswordField(20);
//創(chuàng)建登陸,重置按鈕
JButton?button_reset=new?JButton("重置");
JButton?button_login=new?JButton("登陸");
//設置窗體可見
loginFrame.setVisible(true);
//創(chuàng)建事件監(jiān)聽對象
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("");
}
};
//將文本輸入框,按鈕,事件監(jiān)聽對象添加
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(){
//創(chuàng)建窗體對象
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);
//創(chuàng)建好友按鈕
for(int?i=0;i10;i++)
{
JButton?button_friend=new?JButton("friend"+i);
//創(chuàng)建動作事件監(jiān)聽對象
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(){
//創(chuàng)建窗體,大小,位置,標題
JFrame?chatFrame=new?JFrame();
chatFrame.setSize(400,400);
chatFrame.setTitle("正在聊天中...");
chatFrame.setLocationRelativeTo(null);
//創(chuàng)建聊天記錄,輸入域
JTextArea?area_input=new?JTextArea(10,30);
JTextArea?area_record=new?JTextArea(5,30);
//創(chuàng)建流式分布對象
FlowLayout?layout=new?FlowLayout(FlowLayout.CENTER,0,10);
chatFrame.setLayout(layout);
//創(chuàng)建發(fā)送,關閉按扭
JButton?button_send=new?JButton("發(fā)送");
JButton?button_close=new?JButton("關閉");
//創(chuàng)建動作事件監(jiān)聽對象
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);
//添加按鈕,事件監(jiān)聽對象
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();
}
}
package ch10;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//定義該類繼承自JFrame,實現(xiàn)ActionListener接口
public class LoginTest extends JFrame implements ActionListener
{
//創(chuàng)建JPanel對象
private JPanel jp=new JPanel();
//創(chuàng)建3個標并加入數(shù)組
JLabel name = new JLabel("請輸入用戶名");
JLabel password = new JLabel("請輸入密碼");
JLabel show = new JLabel("");
private JLabel[] jl={name,password,show};
//創(chuàng)建登陸和重置按扭并加入數(shù)組
JButton login = new JButton("登陸");
JButton reset = new JButton("重置");
private JButton[] jb={login,reset};
//創(chuàng)建文本框以及密碼框
private JTextField jName=new JTextField();
private JPasswordField jPassword =new JPasswordField();
public LoginTest()
{
//設置布局管理器為空布局,這里自己擺放按鈕、標簽和文本框
jp.setLayout(null);
for(int i=0;i2;i++)
{
//設置標簽和按扭的位置與大小
jl[i].setBounds(30,20+40*i,180,20);
jb[i].setBounds(30+110*i,100,80,20);
//添加標簽和按扭到JPanel容器中
jp.add(jl[i]);
jp.add(jb[i]);
//為2個按鈕注冊動作事件監(jiān)聽器
jb[i].addActionListener(this);
}
//設置文本框的位置和大小,注意滿足美觀并足夠用戶名的長度
jName.setBounds(130,15,100,20);
//添加文本框到JPanel容器中
jp.add(jName);
//為文本框注冊動作事件監(jiān)聽器
jName.addActionListener(this);
//設置密碼框的位置和大小,注意滿足美觀和足夠密碼的長度
jPassword.setBounds(130,60,100,20);
//添加密碼框到JPanel容器中
jp.add(jPassword);
//設置密碼框中的回顯字符,這里設置美元符號
jPassword.setEchoChar('$');
//為密碼框注冊動作事件監(jiān)聽器
jPassword.addActionListener(this);
//設置用于顯示登陸狀態(tài)的標簽大小位置,并將其添加進JPanel容器
jl[2].setBounds(10,180,270,20);
jp.add(jl[2]);
//添加JPanel容器到窗體中
this.add(jp);
//設置窗體的標題、位置、大小、可見性及關閉動作
this.setTitle("登陸窗口");
this.setBounds(200,200,270,250);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//實現(xiàn)動作監(jiān)聽器接口中的方法actionPerformed
public void actionPerformed(ActionEvent e)
{
//如果事件源為文本框
if(e.getSource()==jName)
{
//切換輸入焦點到密碼框
jPassword.requestFocus();
}
//如果事件源為重置按扭
else if(e.getSource()==jb[1])
{
//清空姓名文本框、密碼框和show標簽中的所有信息
jl[2].setText("");
jName.setText("");
jPassword.setText("");
//讓輸入焦點回到文本框
jName.requestFocus();
}
//如果事件源為登陸按鈕,則判斷登錄名和密碼是否正確
else
{
//判斷用戶名和密碼是否匹配
if(jName.getText().equals("lixiangguo")
String.valueOf(jPassword.getPassword()).equals("19801001"))
{
jl[2].setText("登陸成功,歡迎您的到來!");
}
else
{
jl[2].setText("對不起,您的用戶名或密碼錯誤!");
}
}
}
public static void main(String[] args)
{
//創(chuàng)建LoginTest窗體對象
new LoginTest();
}
}
這個簡單點的
package cn.myself.myproject.FrameProject;import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;import javax.swing.Icon;
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.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;import cn.myself.myproject.employeepj.view.common.CenterWindow;
/**
* 程序功能:QQ登陸面板
* 學習內容:GridBagLayout布局方式的學習
* 以GridBagLayout方式布局的容器,其容器中的每個組件必須由一個GridBagConstrains類的實例對象進行大小,位置等約束。
* @author huliu 2009-06-26
* 難題:a.帳號后面是什么框?
* b.圖片的相對路徑怎么設置?
*/
public class QQRegistBoard extends JFrame{
JPanel p1;
GridBagLayout gb1;
GridBagConstraints gbc1;
JButton btn1,btn2;
JLabel label0,label1,label2,label3,label4,label5;
JTextField text1,text2;
JComboBox box1,box2;
JCheckBox check1,check2;
JList list1;
/**
* 構造方法
*/
public QQRegistBoard(){
super("2009正式版(huliu)");
p1=new JPanel();
gb1=new GridBagLayout();
gbc1=new GridBagConstraints();
p1.setLayout(gb1);//GridBagLayout布局。網(wǎng)袋布局
getContentPane().add(p1); //取得當前容器對象
this.setSize(350,250);
CenterWindow.centerW(this);
Icon icon1 = new ImageIcon("./QQ2.jpg");
// Icon icon1 = new ImageIcon("./QQ.jpg"); //加載圖片,當前目錄下的QQ.jpg
// Icon icon1 = new ImageIcon("src/cn/mysef/images/QQ1.jpg");
label0=new JLabel(icon1);
label1=new JLabel("帳號:");
label2=new JLabel("注冊新帳號");
label3=new JLabel("密碼:");
label4=new JLabel("取回密碼");
label5=new JLabel("狀態(tài):");
text1=new JTextField(10);
text2=new JTextField(10);
String[] str1={"313558851","313857401","690442763"};
box1=new JComboBox(str1);
box1.setEditable(true);//設置ComboBox字段值是否為可編輯
box2=new JComboBox();
check1=new JCheckBox("記住密碼",true);
check2=new JCheckBox("自動登錄");
btn1=new JButton("設置");
btn2=new JButton("登錄");
p1.add(label0,GBC(0,0,3,1,new Insets(5,2,2,4)));//圖片
p1.add(label1,GBC(1,0,1,1,new Insets(4,2,2,4)));
p1.add(box1, GBC(1,1,1,1,new Insets(4,2,2,0)));
//p1.add(text2,GBC(1,1,1,1));
p1.add(label2,GBC(1,2,1,1,new Insets(4,2,2,3)));
p1.add(label3,GBC(2,0,1,1,new Insets(4,2,2,3)));
p1.add(text1, GBC(2,1,1,1,new Insets(5,2,2,3)));
p1.add(label4,GBC(2,2,1,1,new Insets(4,2,2,3)));
p1.add(label5,GBC(3,0,1,1,new Insets(4,2,2,3)));
p1.add(check1,GBC(3,1,1,1,new Insets(4,2,2,3)));
p1.add(check2,GBC(3,2,1,1,new Insets(4,2,2,3)));
p1.add(btn1 ,GBC(4,0,1,1,new Insets(4,2,2,3)));
p1.add(btn2 ,GBC(4,2,1,1,new Insets(4,2,2,3)));
}
/**
* GBC方法:功能是設計以GridBagLayout方式布局的容器(如Panel容器對象)內的組件的位置,大小等約束的。
* @param gridy
* @param gridx
* @param gridwidth
* @param gridheight
* @return GridBagStraints實對象
* Insets(int top, int left, int bottom, int right),與其它組件之間距離(上,左,下,右)
*/
public GridBagConstraints GBC(int gridy,int gridx,int gridwidth,int gridheight,Insets insets){
GridBagConstraints gbc1=new GridBagConstraints();
gbc1.gridx=gridx; //列
gbc1.gridy=gridy; //行
gbc1.gridwidth=gridwidth;//寬度
gbc1.gridheight=gridheight; //高度
//insets=new Insets(1,1,1,1);
gbc1.insets=insets;
return gbc1;
}
public static void main(String[] args){
new QQRegistBoard().setVisible(true);
}}
網(wǎng)站欄目:qq頁面java代碼,java
文章路徑:http://chinadenli.net/article45/dsgshhi.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設計公司、用戶體驗、定制網(wǎng)站、小程序開發(fā)、手機網(wǎng)站建設、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)