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;
}
}
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;
}
}
本文介绍了一个简单的QQ登录界面实现方案,使用Java Swing构建了一个包含图片、文本框、按钮等元素的登录窗口,并设置了窗口的位置、大小及外观风格。
1779

被折叠的 条评论
为什么被折叠?



