久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術(shù)文章
文章詳情頁

java swing 創(chuàng)建一個(gè)簡單的QQ界面教程

瀏覽:149日期:2022-05-26 10:32:44

記錄自己用java swing做的第一個(gè)簡易界面。

LoginAction.java

package com.QQUI0819;import javax.swing.*;import java.awt.event.*;//首先,編寫按鈕?監(jiān)聽器實(shí)現(xiàn)類public class LoginAction implements ActionListener { private int count=0; //當(dāng)前為null,創(chuàng)建后指向界面輸入框 private JTextField ulName; private JTextField ulpass; //創(chuàng)建時(shí),輸入界面類中?輸入框 public LoginAction(JTextField ulName,JTextField ulpass ){ this.ulName=ulName; this.ulpass=ulpass; } //實(shí)現(xiàn)接口中?方法 //當(dāng)勱作發(fā)生時(shí),這個(gè)方法執(zhí)行 public void actionPerformed(ActionEvent e) { //點(diǎn)擊時(shí),就取得界面輸入框?內(nèi)容 //此時(shí)?jtf,指向是界面上那個(gè)輸入框 String u=ulName.getText(); String p=ulName.getText(); System.out.println('賬號(hào)輸入的是 '+u); System.out.println('密碼輸入的是 '+p) if(u.equals('csy123') ||(p.equals('456'))){ //如果輸入正確,彈出新界面 JFrame jf=new JFrame(); jf.setTitle('登陸成功'); jf.setSize(300,400); jf.setLocationRelativeTo(null); jf.setVisible(true); } else { //如果輸入正確,彈出新界面 JFrame jf=new JFrame(); jf.setTitle('登陸失敗'); jf.setSize(300,100); JButton b1 = new JButton('登陸失敗,賬號(hào)和密碼不匹配'); jf.add(b1); jf.setLocationRelativeTo(null); jf.setVisible(true); } }}

QQ.java

package com.QQUI0819;import java.awt.Color;import java.awt.Container;import java.awt.Cursor;import java.awt.Font;import java.awt.Image;import java.util.ArrayList;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPasswordField;import javax.swing.JRootPane;import javax.swing.JTextField;public class QQ extends JFrame{ //用戶名 private JTextField ulName; //密碼 private JPasswordField ulPasswd; //小容器 private JLabel j1; private JLabel j2; private JLabel j3; private JLabel j4; //小按鈕 private JButton b1; //復(fù)選框 private JCheckBox c1; private JCheckBox c2; /** * 初始化QQ登錄頁面 * */ public QQ(){ //設(shè)置登錄窗口標(biāo)題 this.setTitle('QQ登錄'); //去掉窗口的裝飾(邊框) //采用指定的窗口裝飾風(fēng)格 this.getRootPane().setWindowDecorationStyle(JRootPane.NONE); //窗體組件初始化 init(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //設(shè)置布局為絕對(duì)定位 this.setLayout(null); this.setBounds(0, 0, 355, 265); //設(shè)置窗體的圖標(biāo) Image img0 = new ImageIcon('E:藍(lán)杰培訓(xùn)第一周java基礎(chǔ)basicStudysrccomQQUI0819QQlogo.jpg').getImage(); this.setIconImage(img0); //窗體大小不能改變 this.setResizable(false); //居中顯示 this.setLocationRelativeTo(null); //窗體顯示 this.setVisible(true); } /** * 窗體組件初始化 * */ public void init(){ //創(chuàng)建一個(gè)容器,其中的圖片大小和setBounds Container container = this.getContentPane(); j1 = new JLabel(); //設(shè)置背景色 Image img1 = new ImageIcon('E:藍(lán)杰培訓(xùn)第一周java基礎(chǔ)basicStudysrccomQQUI0819QQ.jpg').getImage(); j1.setIcon(new ImageIcon(img1)); j1.setBounds(0, 0, 355, 90); //qq頭像設(shè)定 j2 = new JLabel(); Image img2 = new ImageIcon('E:藍(lán)杰培訓(xùn)第一周java基礎(chǔ)basicStudysrccomQQUI0819QQlogo.jpg').getImage(); j2.setIcon(new ImageIcon(img2)); j2.setBounds(20, 100, 60, 63); //用戶名輸入框 ulName = new JTextField(); ulName.setBounds(100, 100, 150, 20); //注冊(cè)賬號(hào) j3 = new JLabel('注冊(cè)賬號(hào)'); 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); //自動(dòng)登陸 c2 = new JCheckBox('自動(dòng)登陸'); c2.setBounds(185, 155, 80, 15); //登陸按鈕 b1 = new JButton('登錄'); //設(shè)置字體和顏色和手形指針 b1.setFont(new Font('宋體', Font.PLAIN, 12)); b1.setForeground(Color.black); b1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); b1.setBounds(20, 200, 300, 20); //給按鈕添加 //所有組件用容器裝載 this.add(j1); this.add(j2); this.add(j3); this.add(j4); this.add(c1); this.add(c2); this.add(b1); //創(chuàng)建監(jiān)聽器對(duì)象,?約癰?磁 LoginAction lo=new LoginAction(ulName,ulPasswd); b1.addActionListener(lo); container.add(j1); container.add(ulName); container.add(ulPasswd); } public static void main(String[] args) { new QQ(); }}

效果圖

java swing 創(chuàng)建一個(gè)簡單的QQ界面教程

java swing 創(chuàng)建一個(gè)簡單的QQ界面教程

素材

logo:

java swing 創(chuàng)建一個(gè)簡單的QQ界面教程

QQ logo:

java swing 創(chuàng)建一個(gè)簡單的QQ界面教程

補(bǔ)充知識(shí):創(chuàng)建一個(gè)簡單的Java Swing登入窗口

連接數(shù)據(jù)圖就不弄了,要連接數(shù)據(jù)庫的自行添加

為了方便排版,Layout用SpringLayout類型

1.賬號(hào)框采用JTextField 類型

2.密碼框采用JPasswordField類型

兩者的區(qū)別是:

JPasswordField顯示的文本是這樣的:

java swing 創(chuàng)建一個(gè)簡單的QQ界面教程

文本框JTextField顯示的文本是這樣的:

java swing 創(chuàng)建一個(gè)簡單的QQ界面教程

3.建立兩個(gè)JButton,一個(gè)是“登入”按鈕,另一個(gè)是“重置”按鈕

4.建立兩個(gè)Checkbox:一個(gè)是記住密碼,另一個(gè)是隱身登入

5.最后一步加入背景圖

代碼:

package l;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.EventQueue;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.SpringLayout;import javax.swing.JLabel;import java.awt.Font;import javax.swing.JTextField;import javax.swing.JPasswordField;import javax.swing.ImageIcon;import javax.swing.JButton;import java.awt.event.FocusAdapter;import java.awt.event.FocusEvent;import javax.swing.JLayeredPane;import java.awt.Checkbox;public class Login extends JFrame { private JPanel contentPane; private JTextField textField; private JPasswordField passwordField; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() {try { Login frame = new Login(); frame.setVisible(true); //窗口可見 frame.setResizable(false); //設(shè)置登入窗口不能調(diào)整大小 ImageIcon img = new ImageIcon('d:/img.jpg');//這是背景圖片 JLabel imgLabel = new JLabel(img);//將背景圖放在標(biāo)簽里。 frame.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight()); Container cp=frame.getContentPane(); ((JPanel)cp).setOpaque(false);} catch (Exception e) { e.printStackTrace();} } }); } public Login() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); SpringLayout sl_contentPane = new SpringLayout(); contentPane.setLayout(sl_contentPane);JLabel lblNewLabel = new JLabel('賬號(hào):'); lblNewLabel.setFont(new Font('黑體', Font.PLAIN, 19)); sl_contentPane.putConstraint(SpringLayout.NORTH, lblNewLabel, 34, SpringLayout.NORTH, contentPane); sl_contentPane.putConstraint(SpringLayout.WEST, lblNewLabel, 41, SpringLayout.WEST, contentPane); contentPane.add(lblNewLabel);JLabel lblNewLabel_1 = new JLabel('密碼:'); lblNewLabel_1.setFont(new Font('黑體', Font.PLAIN, 19)); sl_contentPane.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 29, SpringLayout.SOUTH, lblNewLabel); sl_contentPane.putConstraint(SpringLayout.WEST, lblNewLabel_1, 0, SpringLayout.WEST, lblNewLabel); contentPane.add(lblNewLabel_1);textField = new JTextField(); textField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) {String temp=textField.getText();if(temp.equals('')) { textField.setForeground(Color.GRAY); //JTextField提示輸入QQ號(hào) textField.setText('請(qǐng)輸入QQ號(hào)');} } public void focusGained(FocusEvent e) {String temp=textField.getText();if(temp.equals('請(qǐng)輸入QQ號(hào)')) { textField.setText('');} } }); sl_contentPane.putConstraint(SpringLayout.NORTH, textField, 1, SpringLayout.NORTH, lblNewLabel); sl_contentPane.putConstraint(SpringLayout.WEST, textField, 52, SpringLayout.EAST, lblNewLabel); sl_contentPane.putConstraint(SpringLayout.EAST, textField, 196, SpringLayout.EAST, lblNewLabel); contentPane.add(textField); textField.setColumns(10);passwordField = new JPasswordField(); sl_contentPane.putConstraint(SpringLayout.NORTH, passwordField, 26, SpringLayout.SOUTH, textField); sl_contentPane.putConstraint(SpringLayout.WEST, passwordField, 52, SpringLayout.EAST, lblNewLabel_1); sl_contentPane.putConstraint(SpringLayout.SOUTH, passwordField, 48, SpringLayout.SOUTH, textField); sl_contentPane.putConstraint(SpringLayout.EAST, passwordField, 201, SpringLayout.EAST, lblNewLabel_1); contentPane.add(passwordField);JButton btnNewButton = new JButton('登入'); sl_contentPane.putConstraint(SpringLayout.SOUTH, btnNewButton, 65, SpringLayout.SOUTH, passwordField); contentPane.add(btnNewButton);JButton button = new JButton('重置'); sl_contentPane.putConstraint(SpringLayout.NORTH, btnNewButton, 2, SpringLayout.NORTH, button); sl_contentPane.putConstraint(SpringLayout.EAST, btnNewButton, -70, SpringLayout.WEST, button); sl_contentPane.putConstraint(SpringLayout.NORTH, button, 32, SpringLayout.SOUTH, passwordField); sl_contentPane.putConstraint(SpringLayout.WEST, button, 242, SpringLayout.WEST, contentPane); button.setFont(new Font('宋體', Font.PLAIN, 19)); contentPane.add(button);Checkbox checkbox = new Checkbox('記住密碼'); sl_contentPane.putConstraint(SpringLayout.WEST, checkbox, 0, SpringLayout.WEST, textField); sl_contentPane.putConstraint(SpringLayout.SOUTH, checkbox, -6, SpringLayout.NORTH, btnNewButton); contentPane.add(checkbox);Checkbox checkbox_1 = new Checkbox('隱身登入'); sl_contentPane.putConstraint(SpringLayout.WEST, checkbox_1, 35, SpringLayout.EAST, checkbox); sl_contentPane.putConstraint(SpringLayout.SOUTH, checkbox_1, 0, SpringLayout.SOUTH, checkbox); contentPane.add(checkbox_1); }}

運(yùn)行截圖:

java swing 創(chuàng)建一個(gè)簡單的QQ界面教程

以上這篇java swing 創(chuàng)建一個(gè)簡單的QQ界面教程就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: qq
相關(guān)文章:
主站蜘蛛池模板: 欧美日本韩国一区二区三区 | 国产视频一二三区 | 亚洲一区在线日韩在线深爱 | 欧美激情在线狂野欧美精品 | 伊人狠狠 | 国产精品一码二码三码在线 | 九九热精品在线 | 久久久久一区二区 | 伊人久久艹| 亚洲天堂一区 | 黄色一级免费观看 | 亚洲精品一区中文字幕乱码 | 亚洲高清视频在线观看 | 在线免费观看黄色 | 免费日韩成人 | 国产成人在线视频 | 91视频在线观看 | 色综合久久天天综合网 | 国产精品久久久久久久一区探花 | 久久成人精品一区二区三区 | 久精品视频 | 午夜精品| 国产精品一区三区 | 毛片网站在线观看 | 一区二区三区免费在线 | 欧美全黄 | 婷婷色视频 | h片在线免费观看 | 91操操| 亚洲情综合五月天 | 日韩在线观看中文字幕 | 毛片在线免费播放 | 女同久久另类99精品国产 | 日本三级中文在线电影 | 一级黄色毛片子 | 精品久久中文字幕 | 四虎影院网站 | www.中文字幕在线 | 国产精品视频久久久 | 亚洲国产欧美在线 | 狠狠草视频 |