1.[代码][Java]代码
package com.myqq.frame;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.Properties;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import com.myqq.action.LoginAction;
public class LoginFrame extends JFrame{
private JLabel backImg;//背景
private JLabel label_1;
private JLabel label_2;
private JTextField userName;//用户名
private JPasswordField pwd;//密码
private JCheckBox recardPwd;//记住密码
private JLabel label_3;
private JCheckBox autoLogin;//自动登入
private JLabel label_4;
private JLabel newUser;
private JLabel findPwd;
private JButton login;//登入
private JButton setting; //关闭
private JPanel panel;
private JPanel loginPanel;
private JPanel pwdPanel;
private JPanel checkPanel;
private JPanel centerPanel;
private JPanel btn_Panel;
public JTextField getUserName() {
return userName;
}
public void setUserName(JTextField userName) {
this.userName = userName;
}
public JPasswordField getPwd() {
return pwd;
}
public void setPwd(JPasswordField pwd) {
this.pwd = pwd;
}
public LoginFrame()
{
super("MY QQ");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
initGUI();
}
/**
* 初始化界面
*/
private void initGUI()
{
// Image toolimage = new ImageIcon(getClass().getClassLoader().getResource("images/Face2/0.gif")).getImage();
// setIconImage(toolimage);
panel = new JPanel();
//panel.setBackground(Color.WHITE);
panel.setLayout(new BorderLayout());
backImg = new JLabel();
ImageIcon image = new ImageIcon(getClass().getClassLoader().getResource("images/backImg.jpg"));
backImg.setIcon(image);
panel.add(backImg,"North");
//panel.setLayout(new GridLayout(3,0));
label_1 = new JLabel("用户帐号:");
setFonts(label_1);
label_2 = new JLabel("用户密码:");
setFonts(label_2);
userName = new JTextField(12);
pwd = new JPasswordField(12);
loginPanel = new JPanel();
loginPanel.add(label_1);
loginPanel.add(userName);
newUser = new JLabel("新用户注册");
newUser.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
Properties properties = System.getProperties();
String s = properties.getProperty("os.name");
System.out.println((new StringBuilder()).append("当前的操作系统名称: ").append(s).toString());
if (s.indexOf("LINUX") != -1)
try {
Runtime.getRuntime().exec("HTMLview http://www.qq.com");
} catch (IOException e1) {
e1.printStackTrace();
}
else
if (s.indexOf("Windows") != -1)
{
try {
Runtime.getRuntime().exec("explorer http://www.qq.com");
} catch (IOException e1) {
e1.printStackTrace();
}
} else
{
JOptionPane.showMessageDialog(LoginFrame.this, "未知操作系统");
System.out.println((new StringBuilder()).append("未知的操作系统: ").append(s).toString());
throw new RuntimeException("Unknown OS.");
}
}
});
newUser.setCursor(new Cursor(Cursor.HAND_CURSOR));
newUser.setForeground(Color.blue);
setFonts(newUser);
loginPanel.add(newUser);
loginPanel.setBackground(Color.WHITE);
pwdPanel = new JPanel();
pwdPanel.add(label_2);
pwdPanel.add(pwd);
findPwd = new JLabel("找回密码 ");
findPwd.setCursor(new Cursor(Cursor.HAND_CURSOR));
findPwd.setForeground(Color.blue);
setFonts(findPwd);
pwdPanel.add(findPwd);
pwdPanel.setBackground(Color.WHITE);
checkPanel = new JPanel();
recardPwd = new JCheckBox();
recardPwd.setBackground(Color.white);
label_3 = new JLabel("记住密码");
setFonts(label_3);
autoLogin = new JCheckBox();
autoLogin.setBackground(Color.white);
label_4 = new JLabel("自动登入");
setFonts(label_4);
checkPanel.add(recardPwd);
checkPanel.add(label_3);
checkPanel.add(autoLogin);
checkPanel.add(label_4);
checkPanel.setBackground(Color.WHITE);
centerPanel = new JPanel();
centerPanel.setBackground(Color.WHITE);
centerPanel.setBorder(new TitledBorder(""));
centerPanel.setLayout(new GridLayout(3,0));
centerPanel.add(loginPanel);
centerPanel.add(pwdPanel);
centerPanel.add(checkPanel);
btn_Panel = new JPanel();
//btn_Panel.setLayout(new FlowLayout(FlowLayout.CENTER,15,0));
login = new JButton("登入");
login.addActionListener(new LoginAction(this));
setFonts(login);
setting = new JButton("设置");
setFonts(setting);
btn_Panel.add(login);
btn_Panel.add(setting);
btn_Panel.setBackground(new Color(235,243,249));
panel.add(centerPanel);
panel.add(btn_Panel,"South");
add(panel);
}
/*
* 设置字体
*/
private void setFonts(JComponent c)
{
c.setFont(new Font("微软雅黑",Font.PLAIN,12));
}
}