24.QQ登录界面
转自:https://www.cnblogs.com/A--Q/p/6523468.html
效果:

package com.lvshitech.gui;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class QQLoginPage {
JTextField username;
JPasswordField password;
public static void main(String[] args) {
QQLoginPage login = new QQLoginPage();
login.init();
}
public void init() {
// 创建窗体
JFrame frame = new JFrame("QQ 登录(这是一个小Demo)");
frame.setBackground(new Color(235, 242, 249)); // 设置窗体背景颜色
frame.setLocation(440, 150); // 设置窗体位置
frame.setLayout(null); // 手工布局
frame.setSize(420, 330); // 设置窗口的大小
// 创建图片
JLabel imageLabel = new JLabel(new ImageIcon("images/qq.jpg")); // 添加图片
imageLabel.setSize(90, 90);
imageLabel.setLocation(35, 140);
JLabel topImage = new JLabel(new ImageIcon("images/top.jpg")); // 添加图片
topImage.setSize(405, 130);
topImage.setLocation(0, 0);
Label ac = new Label("注册帐号");
ac.setForeground(Color.BLUE);
ac.setSize(50, 30);
ac.setLocation(320, 144);
Label pwd = new Label("找回密码");
pwd.setForeground(Color.BLUE);
pwd.setSize(50, 30);
pwd.setLocation(320, 180);
username = new JTextField();
username.setSize(180, 28);
username.setLocation(135, 146);
password = new JPasswordField();
password.setSize(180, 28);
password.setLocation(135, 181);
Checkbox cb1 = new Checkbox("记住密码");
cb1.setSize(65, 20);
cb1.setLocation(136, 220);
Checkbox cb2 = new Checkbox("自动登录");
cb2.setSize(65, 20);
cb2.setLocation(250, 220);
JButton loginBtn = new JButton("登录");
loginBtn.setSize(180, 30);
loginBtn.setLocation(135, 250);
// 按钮事件
loginBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ("admin".equals(username.getText()) && "123".equals(password.getText())) {
JOptionPane.showMessageDialog(null, "登录成功", "提示信息!", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误!", "信息提示!", JOptionPane.ERROR_MESSAGE);
}
}
});
// 添加到框架中
frame.add(imageLabel);
frame.add(topImage);
frame.add(ac);
frame.add(pwd);
frame.add(username);
frame.add(password);
frame.add(cb1);
frame.add(cb2);
frame.add(loginBtn);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

浙公网安备 33010602011771号