package ch10;

創(chuàng)新互聯(lián)是一家網(wǎng)站設計公司,集創(chuàng)意、互聯(lián)網(wǎng)應用、軟件技術為一體的創(chuàng)意網(wǎng)站建設服務商,主營產(chǎn)品:成都響應式網(wǎng)站建設、品牌網(wǎng)站制作、營銷型網(wǎng)站。我們專注企業(yè)品牌在網(wǎng)站中的整體樹立,網(wǎng)絡互動的體驗,以及在手機等移動端的優(yōu)質(zhì)呈現(xiàn)。網(wǎng)站設計制作、成都網(wǎng)站制作、移動互聯(lián)產(chǎn)品、網(wǎng)絡運營、VI設計、云產(chǎn)品.運維為核心業(yè)務。為用戶提供一站式解決方案,我們深知市場的競爭激烈,認真對待每位客戶,為客戶提供賞析悅目的作品,網(wǎng)站的價值服務。
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();
}
}
這個簡單點的
是javeSE。主要用來編寫一些界面程序,帶窗口的。
ME是專門用來手機開發(fā)的。不過前途不咋滴了。
EE是用來進行企業(yè)級開發(fā)的。多少是BS編程,就是網(wǎng)站類程序。
這3個的基本的java基礎類都是一樣 的。
區(qū)別是:
SE含有SWing等界面類。
ME有很多對手機硬件操作的類。
EE有很多WEB開發(fā)的類。
希望對你有所幫助!o(∩_∩)o 哈哈
1、swing的界面可以直接用netbeans畫出來嘛。
2、可以把輸出的聊天內(nèi)容都放在一個StringBuffer里,每打出一句話,就把這句話追加在StringBuffer,然后把StringBuffer里的內(nèi)容輸出到Textarea中。
3、好友列表可以用JList
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登陸面板
* 學習內(nèi)容: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容器對象)內(nèi)的組件的位置,大小等約束的。
* @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);
}}
這里有,比較簡單的一個實現(xiàn),你可以參考,文章下面有下載鏈接
網(wǎng)站標題:qq界面java源代碼,java仿聊天系統(tǒng)源碼
分享網(wǎng)址:http://chinadenli.net/article7/dsgeeij.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供自適應網(wǎng)站、定制開發(fā)、響應式網(wǎng)站、靜態(tài)網(wǎng)站、外貿(mào)建站、網(wǎng)站設計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)