Java Swing 版 QQ
public class LoginFrame extends MyJCFrame {
private static final long serialVersionUID = 1L;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginFrame frame = new LoginFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LoginFrame() {
initComponents();
initAction();
}
private void initComponents(){
setTitle("JQ2011");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 338, 260);
conterWindows(WindowsLocation.CENTER);
setDefaultBackgroundImage(true);
setResizable(false);
setAlwaysOnTop(true);
contentPane.setBackground(new Color(255,255,255,0));
setContentPane(contentPane);
GridBagLayout gbl_contentPane = new GridBagLayout();
gbl_contentPane.columnWidths = new int[]{0, 0};
gbl_contentPane.rowHeights = new int[]{92, 0, 32, 0};
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
gbl_contentPane.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
contentPane.setLayout(gbl_contentPane);
{
topImagePanel = new JImagePane();
topImagePanel.setBackground(new Color(255,255,255));
topImagePanel.setImage(Toolkit.getDefaultToolkit().getImage(IMconst.IMAGE_DIR + "/QQ.png"));
GridBagConstraints gbc_topImagePanel = new GridBagConstraints();
gbc_topImagePanel.insets = new Insets(0, 0, 0, 0);
gbc_topImagePanel.fill = GridBagConstraints.BOTH;
gbc_topImagePanel.gridx = 0;
gbc_topImagePanel.gridy = 0;
contentPane.add(topImagePanel, gbc_topImagePanel);
}
{
centerImagePanel = new JImagePane();
GridBagConstraints gbc_centerImagePanel = new GridBagConstraints();
gbc_centerImagePanel.insets = new Insets(0, 0, 0, 0);
gbc_centerImagePanel.fill = GridBagConstraints.BOTH;
gbc_centerImagePanel.gridx = 0;
gbc_centerImagePanel.gridy = 1;
contentPane.add(centerImagePanel, gbc_centerImagePanel);
{
GridBagLayout gbl_centerImagePanel = new GridBagLayout();
gbl_centerImagePanel.columnWidths = new int[]{108, 182, 0};
gbl_centerImagePanel.rowHeights = new int[]{36, 0};
gbl_centerImagePanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
gbl_centerImagePanel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
centerImagePanel.setLayout(gbl_centerImagePanel);
{
avatarImagePanel = new JImagePane();
avatarImagePanel.setImage(Toolkit.getDefaultToolkit().getImage(IMconst.IMAGE_DIR + "/QQ_LOGO.png"));
GridBagConstraints gbc_avatarImagePanel = new GridBagConstraints();
gbc_avatarImagePanel.insets = new Insets(0, 0, 0, 5);
gbc_avatarImagePanel.fill = GridBagConstraints.BOTH;
gbc_avatarImagePanel.gridx = 0;
gbc_avatarImagePanel.gridy = 0;
centerImagePanel.add(avatarImagePanel, gbc_avatarImagePanel);
}
{
panel = new JPanel();
GridBagConstraints gbc_panel = new GridBagConstraints();
gbc_panel.fill = GridBagConstraints.BOTH;
gbc_panel.gridx = 1;
gbc_panel.gridy = 0;
centerImagePanel.add(panel, gbc_panel);
{
GridBagLayout gbl_panel = new GridBagLayout();
gbl_panel.columnWidths = new int[]{180, 39, 0};
gbl_panel.rowHeights = new int[]{42, 29, 0, 0};
gbl_panel.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
gbl_panel.rowWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
panel.setLayout(gbl_panel);
{
nameInput = new JCComboBox();
nameInput.setEditable(true);
nameInput.setPreferredSize(new Dimension(180, 28));
nameInput.setModel(new DefaultComboBoxModel(new String[] {"死腾讯-你妹", "死马化腾-你妹", "\u7535\u89C6\u5267\u5076\u5BB6\u5EA6\u641C", "\u4E0A\u5927\u6982\u591A\u5C11"}));
nameInput.setSelectedIndex(1);
GridBagConstraints gbc_nameInput = new GridBagConstraints();
gbc_nameInput.anchor = GridBagConstraints.SOUTHWEST;
gbc_nameInput.insets = new Insets(0, 0, 5, 5);
gbc_nameInput.gridx = 0;
gbc_nameInput.gridy = 0;
panel.add(nameInput, gbc_nameInput);
}
{
registerLabel = new JCLabel("注册");
registerLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
registerLabel.setForeground(new Color(22, 112, 235));
GridBagConstraints gbc_registerLabel = new GridBagConstraints();
gbc_registerLabel.anchor = GridBagConstraints.WEST;
gbc_registerLabel.insets = new Insets(5, 0, 5, 0);
gbc_registerLabel.gridx = 1;
gbc_registerLabel.gridy = 0;
panel.add(registerLabel, gbc_registerLabel);
}
{
pwdInput = new JCLimitedPassword(20);
pwdInput.setPreferredSize(nameInput.getPreferredSize());
GridBagConstraints gbc_pwdInput = new GridBagConstraints();//54,97,138
gbc_pwdInput.anchor = GridBagConstraints.WEST;
gbc_pwdInput.insets = new Insets(0, 0, 0, 5);
gbc_pwdInput.gridx = 0;
gbc_pwdInput.gridy = 1;
pwdInput.setText("0000");
panel.add(pwdInput, gbc_pwdInput);
}
{
retrieveLabel = new JCLabel("找回");
retrieveLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
retrieveLabel.setForeground(registerLabel.getForeground());
GridBagConstraints gbc_retrieveLabel = new GridBagConstraints();
gbc_retrieveLabel.anchor = GridBagConstraints.WEST;
gbc_retrieveLabel.insets = new Insets(5, 0, 5, 0);
gbc_retrieveLabel.gridx = 1;
gbc_retrieveLabel.gridy = 1;
panel.add(retrieveLabel, gbc_retrieveLabel);
}
{
panel_1 = new JPanel();
FlowLayout flowLayout_1 = (FlowLayout) panel_1.getLayout();
flowLayout_1.setAlignment(FlowLayout.LEFT);
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
gbc_panel_1.gridwidth = 2;
gbc_panel_1.fill = GridBagConstraints.HORIZONTAL;
gbc_panel_1.gridx = 0;
gbc_panel_1.gridy = 2;
panel.add(panel_1, gbc_panel_1);
}
{
bar = new JMenuBar();
bar.setOpaque(false);
bar.setBorder(new EmptyBorder(0, 0, 0, 0));
bar.setBorderPainted(false);
bar.setLayout(new GridLayout(1, 2));
bar.setPreferredSize(new Dimension(40, 20));
bar.setFocusable(false);
panel_1.add(bar);
{
menu = new JCMenu("QQJ");
menu.setShowWhenRollover(false);
menu.setRolloverEnabled(false);
bar.add(menu);
JCMenuItem menuItem = new JCMenuItem();
menuItem.setText("我在线");
menu.add(menuItem);
}
}
}
}
{
rememberCheckBox = new JCCheckBox("记住密码");
panel_1.add(rememberCheckBox);
}
{
automaticLoginCheckBox = new JCCheckBox("自动登陆");
panel_1.add(automaticLoginCheckBox);
}
}
}
{
endPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) endPanel.getLayout();
flowLayout.setAlignment(FlowLayout.RIGHT);
endPanel.setBackground(new Color(190,230,250));
GridBagConstraints gbc_endPanel = new GridBagConstraints();
gbc_endPanel.fill = GridBagConstraints.BOTH;
gbc_endPanel.gridx = 0;
gbc_endPanel.gridy = 2;
contentPane.add(endPanel, gbc_endPanel);
{
loginButton = new JCButton("安全登陆");
loginButton.setPreferredSize(new Dimension(80,23));
endPanel.add(loginButton);
}
}
}
/**
* 初始化事件
*/
private void initAction(){
//找回密码多选按钮
UIUtil.actionLabel(retrieveLabel, new AbstractAction() {
private static final long serialVersionUID = 1314650981076868723L;
public void actionPerformed(ActionEvent e)
{
System.out.println("retrieveLabel");
}
});
//注册多选按钮
UIUtil.actionLabel(registerLabel, new AbstractAction(){
private static final long serialVersionUID = 1314650981076868723L;
public void actionPerformed(ActionEvent e)
{
System.out.println("registerLabel");
}
});
//自动登录事件
automaticLoginCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(automaticLoginCheckBox.isSelected()){
rememberCheckBox.setSelected(true);//设置记住密码
}
}
});
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JCMessageBox.createInformationMessageBox(LoginFrame.this, "提示", "登录成功").open();
}
});
}
@Override
public void setVisible(boolean b) {
super.setVisible(b);
initValues();
}
/**
* 初始化界面默认属性
*/
private void initValues(){
pwdInput.requestFocus();
}
private JCMenu menu;
private JCCheckBox automaticLoginCheckBox, rememberCheckBox;
private JPanel endPanel, panel_1, panel;
private JCButton loginButton;
private JCLabel retrieveLabel, registerLabel;
private JImagePane topImagePanel;
private JImagePane centerImagePanel, avatarImagePanel;
private JCComboBox nameInput;
private JCLimitedPassword pwdInput;
private JMenuBar bar;
}