QQLoginFrame 登录界面

本文介绍了一个简单的QQ登录界面实现方案,使用Java Swing构建了一个包含图片、文本框、按钮等元素的登录窗口,并设置了窗口的位置、大小及外观风格。
package com.hbqy.LoginFrameUI.lixinghai;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Label;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author 11:19:42 PM
 */
public class QQLoginFrame extends JFrame {
    public static void main(String[] args) {
        new QQLoginFrame().launchFrame();
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | UnsupportedLookAndFeelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * 静态属性
     */

    /**
     * 加载运行窗口界面
     */
    private void launchFrame() {
        // setLocation(500, 500);
        setTitle("腾讯科技");
        setSize(400, 330);// 设置窗口的大小
        setLocationRelativeTo(null);// 将窗口放置在屏幕的中心位置
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);// 设置默认关闭方式
        add(northPanel(), BorderLayout.NORTH);// 将北部面板添加到窗口的北部
        add(southPanel());// 添加南部面板
        setVisible(true);// 设置窗口可见
    }

    /**
     * 获取南部面板
     *
     * @return
     */
    private JPanel northPanel() {
        JPanel northPanel = new JPanel();
        ImageIcon icon = new ImageIcon(this.getClass().getResource("qqpicture.PNG"));
        northPanel.setLayout(new BorderLayout());
        JLabel la = new JLabel();
        la.setIcon(icon);// 必须是swing中的JLabel才有setIcon()方法
        northPanel.add(la);
        return northPanel;
    }

    /**
     * 获取南部面板
     *
     * @return
     */
    private JPanel southPanel() {
        JPanel southPanel = new JPanel();
        southPanel.setLayout(new BorderLayout());
        southPanel.add(southwestPanel(), BorderLayout.WEST);
        southPanel.add(southeastPanel());
        return southPanel;
    }

    /**
     * 获取东南部面板
     *
     * @return
     */
    private JPanel southeastPanel() {
        JPanel southeastPanel = new JPanel();
        southeastPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));// 设置流式布局的同时,设置位置,以及组件之间的水平间距和垂直间距
        JTextField uersName = new JTextField();
        uersName.setPreferredSize(new Dimension(150, 26));
        JLabel registName = new JLabel("   注册账号");
        Font font = new Font("微软雅黑", Font.BOLD, 13);
        registName.setFont(font);
        registName.setForeground(new Color(39, 134, 228));// 设置标签的前景色RGB色彩三原色
        southeastPanel.add(new Label("                                    "));
        southeastPanel.add(uersName);
        southeastPanel.add(registName);
        // *************************************
        JTextField password = new JTextField();
        password.setPreferredSize(new Dimension(150, 26));
        JLabel findPassword = new JLabel("   找回密码");
        findPassword.setFont(font);
        findPassword.setForeground(new Color(39, 134, 228));// 设置标签的前景色RGB色彩三原色
        southeastPanel.add(password);
        southeastPanel.add(findPassword);
        // *************************************
        JCheckBox remeberPassword = new JCheckBox("记住密码");
        remeberPassword.setFont(font);
        JLabel blankFilled = new JLabel("                       ");
        JCheckBox autoLogin = new JCheckBox("自动登录");
        autoLogin.setFont(font);
        southeastPanel.add(remeberPassword);
        southeastPanel.add(blankFilled);
        southeastPanel.add(autoLogin);
        // *************************************
        JButton loginButton = new JButton("安全登录");
        loginButton.setFont(font);
        loginButton.setPreferredSize(new Dimension(215, 24));
        loginButton.setBackground(new Color(39, 134, 228));
        southeastPanel.add(loginButton);
        return southeastPanel;
    }

    /**
     * 获取西北部的面板
     *
     * @return
     */
    private JPanel southwestPanel() {
        JPanel southwestPanel = new JPanel();
        ImageIcon icon = new ImageIcon(this.getClass().getResource("qqface.PNG"));
        JLabel la = new JLabel(icon);
        la.setIcon(icon);
        southwestPanel.add(la);
        return southwestPanel;
    }
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值