java實(shí)現(xiàn)簡單QQ登錄界面
本文實(shí)例為大家分享了java實(shí)現(xiàn)簡單QQ登錄界面的具體代碼,供大家參考,具體內(nèi)容如下
java在圖形界面,不是太強(qiáng)項(xiàng),但不是不可以做,它的開源是very nice!
實(shí)現(xiàn)代碼如下(想實(shí)現(xiàn)完美的界面,可能要更多coding的支持):
package com.ts.x.swing; import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Font; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; 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.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JRootPane; import javax.swing.JTextField; public class QQ extends JFrame{ private static final long serialVersionUID = -6788045638380819221L; //用戶名 private JTextField ulName; //密碼 private JPasswordField ulPasswd; //小容器 private JLabel j1; private JLabel j2; private JLabel j3; private JLabel j4; //小按鈕 private JButton b1; private JButton b2; private JButton b3; //復(fù)選框 private JCheckBox c1; private JCheckBox c2; //列表框 private JComboBox<String> cb1; /** * 初始化QQ登錄頁面 * */ public QQ(){ //設(shè)置登錄窗口標(biāo)題 this.setTitle("QQ登錄"); //去掉窗口的裝飾(邊框) // this.setUndecorated(true); //采用指定的窗口裝飾風(fēng)格 this.getRootPane().setWindowDecorationStyle(JRootPane.NONE); //窗體組件初始化 init(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //設(shè)置布局為絕對定位 this.setLayout(null); this.setBounds(0, 0, 355, 265); //設(shè)置窗體的圖標(biāo) Image img0 = new ImageIcon("D:/logo.png").getImage(); this.setIconImage(img0); //窗體大小不能改變 this.setResizable(false); //居中顯示 this.setLocationRelativeTo(null); //窗體顯示 this.setVisible(true); } /** * 窗體組件初始化 * */ public void init(){ //創(chuàng)建一個容器,其中的圖片大小和setBounds第三、四個參數(shù)要基本一致(需要自己計(jì)算裁剪) Container container = this.getContentPane(); j1 = new JLabel(); //設(shè)置背景色 Image img1 = new ImageIcon("D:/bgimg.png").getImage(); j1.setIcon(new ImageIcon(img1)); j1.setBounds(0, 0, 355, 265); //qq頭像設(shè)定 j2 = new JLabel(); Image img2 = new ImageIcon("D:/hdimg.png").getImage(); j2.setIcon(new ImageIcon(img2)); j2.setBounds(40, 95, 50, 53); //用戶名輸入框 ulName = new JTextField(); ulName.setBounds(100, 100, 150, 20); //注冊賬號 j3 = new JLabel("注冊賬號"); j3.setBounds(260, 100, 70, 20); //密碼輸入框 ulPasswd = new JPasswordField(); ulPasswd.setBounds(100, 130, 150, 20); //找回密碼 j4= new JLabel("找回密碼"); j4.setBounds(260, 130, 70, 20); //記住密碼 c1 = new JCheckBox("記住密碼"); c1.setBounds(105, 155, 80, 15); //自動登陸 c2 = new JCheckBox("自動登陸"); c2.setBounds(185, 155, 80, 15); //用戶登陸狀態(tài)選擇 cb1 = new JComboBox<String>(); cb1.addItem("在線"); cb1.addItem("隱身"); cb1.addItem("離開"); cb1.setBounds(40, 150, 55, 20); //登陸按鈕 b1 = new JButton("登錄"); //設(shè)置字體和顏色和手形指針 b1.setFont(new Font("宋體", Font.PLAIN, 12)); b1.setForeground(Color.RED); b1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); b1.setBounds(280, 200, 65, 20); //給按鈕添加 b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if("登錄".equals(cmd)){ String username = ulName.getText(); String userpassword = ulPasswd.getText(); if(username.equals("tskk") && userpassword.equals("123456")){ JOptionPane.showConfirmDialog(null, "登錄成功"); }else{ JOptionPane.showConfirmDialog(null, "登錄失敗"); } } } }); //多賬號 b2 = new JButton("多賬號"); b2.setBounds(5, 200, 75, 20); //設(shè)置 b3 = new JButton("設(shè)置"); b3.setBounds(100, 200, 65, 20); //所有組件用容器裝載 j1.add(j2); j1.add(j3); j1.add(j4); j1.add(c1); j1.add(c2); j1.add(cb1); j1.add(b1); j1.add(b2); j1.add(b3); container.add(j1); container.add(ulName); container.add(ulPasswd); } public static void main(String[] args) { new QQ(); } }
運(yùn)行結(jié)果界面為:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java中Boolean與字符串或者數(shù)字1和0的轉(zhuǎn)換實(shí)例
下面小編就為大家?guī)硪黄狫ava中Boolean與字符串或者數(shù)字1和0的轉(zhuǎn)換實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07Java?synchronized關(guān)鍵字性能考量及優(yōu)化探索
這篇文章主要為大家介紹了Java?synchronized關(guān)鍵字性能考量及優(yōu)化探索示例分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12SpringBoot?整合?ShardingSphere4.1.1實(shí)現(xiàn)分庫分表功能
ShardingSphere是一套開源的分布式數(shù)據(jù)庫中間件解決方案組成的生態(tài)圈,它由Sharding-JDBC、Sharding-Proxy和Sharding-Sidecar(計(jì)劃中)這3款相互獨(dú)立的產(chǎn)品組成,本文給大家介紹SpringBoot?整合?ShardingSphere4.1.1實(shí)現(xiàn)分庫分表,感興趣的朋友一起看看吧2023-12-12