java模仿實(shí)現(xiàn)QQ登錄界面
本文實(shí)例為大家分享了java模仿實(shí)現(xiàn)qq登錄界面的具體代碼,供大家參考,具體內(nèi)容如下
這是我模仿QQ2015版界面,實(shí)現(xiàn)的基本功能有登陸驗(yàn)證,重置等,當(dāng)然直接復(fù)制代碼運(yùn)行是不一樣的,還要注意自己插入自己的圖片。
結(jié)果截圖如下所示:
代碼:
import java.awt.BorderLayout;import java.awt.Color;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.Image;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Arrays;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;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 QQ2015 extends JFrame implements ActionListener {JFrame loginFrame;// 復(fù)選框private JCheckBox jc1;private JCheckBox jc2;// 用戶名private JTextField username;// 密碼private JPasswordField password;// 錯(cuò)誤消息提示JLabel mes;// 創(chuàng)建一個(gè)HashMap,用以保存帳號(hào)和密碼HashMap<String, String> users = new HashMap<String, String>();// 主函數(shù)入口public static void main(String[] args) {QQ2015 qq2015 = new QQ2015();qq2015.showLoginFrame();}// 構(gòu)造方法public QQ2015() {users.put('123456', '123456');users.put('302795036', '123456');users.put('123', '123456');}// 創(chuàng)建登陸界面方法public void showLoginFrame() {loginFrame = new JFrame();// 設(shè)置大小,位置,標(biāo)題loginFrame.setSize(410, 380);loginFrame.setTitle('修衡-QQ2015');loginFrame.setLocationRelativeTo(null);// 創(chuàng)建邊界布局對(duì)象loginFrame.setLayout(new BorderLayout());JPanel panelTop = new JPanel(new FlowLayout());JPanel panelCenter = new JPanel(new GridLayout(3, 1));JPanel panelFooter = new JPanel(new GridLayout(2, 1));JPanel panelFooter1 = new JPanel(new FlowLayout());JPanel panelFooter2 = new JPanel(new FlowLayout());panelFooter.add(panelFooter1);panelFooter.add(panelFooter2);JPanel panelLeft = new JPanel(new GridLayout(1, 1));JPanel panelRight = new JPanel(new GridLayout(3, 1));loginFrame.add('North', panelTop);loginFrame.add('Center', panelCenter);loginFrame.add('South', panelFooter);loginFrame.add('West', panelLeft);loginFrame.add('East', panelRight);(new BorderLayout()).setHgap(50);// 插入圖片Image im = new ImageIcon('imgs/qq.png').getImage();im = im.getScaledInstance(-1, 90, DO_NOTHING_ON_CLOSE);loginFrame.setIconImage(im);JLabel tl = new JLabel(new ImageIcon('imgs/top.png'));panelTop.add(tl);// 可以設(shè)置panelTop背景顏色// panelTop.setBackground(Color.YELLOW);JLabel ll = new JLabel(new ImageIcon('imgs/left.png'));panelLeft.add(ll);// 創(chuàng)建注冊(cè)賬號(hào)和找回密碼標(biāo)簽JLabel reg_name = new JLabel(' 注冊(cè)賬號(hào) ');JLabel find_password = new JLabel(' 找回密碼 ');reg_name.setForeground(Color.BLUE);find_password.setForeground(Color.BLUE);// 創(chuàng)建帳號(hào)和密碼輸入框username = new JTextField(18);password = new JPasswordField(18);// 復(fù)選框jc1 = new JCheckBox('記住密碼 ');jc2 = new JCheckBox('自動(dòng)登錄');JLabel nul1 = new JLabel(' ');JLabel nul2 = new JLabel(' ');// 錯(cuò)誤消息提示標(biāo)簽mes = new JLabel();mes.setForeground(Color.RED);// 部分布局JPanel pancener = new JPanel(new FlowLayout());pancener.add(jc1);pancener.add(nul1);pancener.add(jc2);// 創(chuàng)建登陸,重置按鈕JButton button_reset = new JButton(' 重 置 ');JButton button_login = new JButton(' 登 陸 ');button_login.setBackground(Color.pink);// 窗體大小不能改變loginFrame.setResizable(false);// 設(shè)置窗體可見loginFrame.setVisible(true);// 將文本輸入框,按鈕,事件監(jiān)聽對(duì)象等添加panelCenter.add(username);panelCenter.add(password);panelCenter.add(pancener);panelRight.add(reg_name);panelRight.add(find_password);panelFooter1.add(button_reset);panelFooter1.add(nul2);panelFooter1.add(button_login);panelFooter2.add(mes);button_reset.addActionListener(this);button_login.addActionListener(this);// reg_name.addActionListener(this);}public void actionPerformed(ActionEvent e) {String str = e.getActionCommand();boolean f = false;String pw = null;// 重置事件if (str.equals(' 重 置 ')) {username.setText('');password.setText('');mes.setText('');}// 登錄事件if (str.equals(' 登 陸 ')) {mes.setText('');Set<Map.Entry<String, String>> set = users.entrySet();for (Map.Entry<String, String> me : set) {if (username.getText().trim().equals(me.getKey())) {f = true;pw = me.getValue();break;}}if (f) {// if (password.getPassword().equals(pw)) {if (password.getText().trim().equals(pw)) {JOptionPane.showMessageDialog(null, '登錄成功');} else {mes.setText('溫馨提示:密碼為空或錯(cuò)誤,請(qǐng)重新輸入!');}} else {mes.setText('溫馨提示:帳號(hào)為空或錯(cuò)誤,請(qǐng)重新輸入!');}}}}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 網(wǎng)易云游戲丟包高解決方法2. 支付寶花唄支持哪些實(shí)體店鋪 支付寶螞蟻花唄可以掃一掃付款嗎3. 酷狗唱唱怎么合唱歌曲4. 微博贊了馬上取消對(duì)方會(huì)看到嗎5. WPS表格怎么進(jìn)行拼寫檢查6. CAD2022安裝序列號(hào)和產(chǎn)品密鑰7. wps表格關(guān)閉自動(dòng)重調(diào)尺寸以適應(yīng)內(nèi)容方法分享8. 拼多多最后砍不動(dòng)了怎么辦9. 釘釘怎么查看直播時(shí)長(zhǎng)和觀看人數(shù)?釘釘直播時(shí)長(zhǎng)和觀看人數(shù)查看方法10. 美圖秀秀怎么編輯證件上的文字信息 編輯證件上的文字信息操作流程一覽
