QQ框架:
import javax.swing.*;
import java.awt.*;
public class QQFrame extends JFrame{
public QQFrame()
{
super("QQ2010");
setSize(340,250);
setLocation(250,300);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainPanel mp=new MainPanel();
add(mp);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setVisible(true);
}
public static void main(String[] args)
{
QQFrame f=new QQFrame();
}
}
class MainPanel extends Panel{
GridBagLayout gbl=new GridBagLayout();
public MainPanel()
{
super();
setLayout(gbl);
ImageIcon i1=new ImageIcon("D://my document//photoshops//Icon//QQ.jpg");
JLabel QQphoto=new JLabel(i1,SwingConstants.CENTER);
JLabel IDLabel=new JLabel("账号:");
JTextField ID=new JTextField();
JLabel register=new JLabel(" 注册新账号");
JLabel passwordLabel=new JLabel("密码:");
JPasswordField password=new JPasswordField();
JLabel re=new JLabel(" 找回密码");
JCheckBox autoLoad=new JCheckBox("自动登录");
JCheckBox Remeber=new JCheckBox("记住密码");
JCheckBox hidingLoad=new JCheckBox("隐身登录");
JButton set=new JButton("设置");
JButton load=new JButton("登录");
addComponent(QQphoto, 0, 0, 11, 3,11,3, GridBagConstraints.NONE,GridBagConstraints.NORTH);
addComponent(IDLabel,0,4,2,2,10,2, GridBagConstraints.NONE,GridBagConstraints.EAST);
addComponent(ID, 2, 4, 6, 2,40,2, GridBagConstraints.HORIZONTAL,GridBagConstraints.WEST);
addComponent(register,8,4,3,2,20,2,GridBagConstraints.NONE,GridBagConstraints.WEST);
addComponent(passwordLabel, 0, 7, 2, 2,10,2, GridBagConstraints.NONE,GridBagConstraints.EAST);
addComponent(password, 2, 7, 6, 2, 40,2, GridBagConstraints.HORIZONTAL,GridBagConstraints.WEST);
addComponent(re, 8, 7, 3, 2, 20,2, GridBagConstraints.NONE,GridBagConstraints.WEST);
addComponent(autoLoad, 0, 11, 3, 1,3,1, GridBagConstraints.NONE,GridBagConstraints.CENTER);
addComponent(Remeber, 3, 11, 5, 1, 3,1, GridBagConstraints.NONE,GridBagConstraints.CENTER);
addComponent(hidingLoad, 8, 11, 3, 1,3,1,GridBagConstraints.NONE,GridBagConstraints.CENTER);
addComponent(set, 0, 13, 4, 2, 3,2, GridBagConstraints.NONE,GridBagConstraints.WEST);
addComponent(load, 7, 13, 4, 2, 3,2, GridBagConstraints.NONE,GridBagConstraints.EAST);
}
private void addComponent(Component component,int gridx,int gridy,int gridwidth,int gridheight,int weightx,int weighty,int fill,int anchor)
{
GridBagConstraints constraints=new GridBagConstraints();
constraints.gridx=gridx;
constraints.gridy=gridy;
constraints.gridwidth=gridwidth;
constraints.gridheight=gridheight;
constraints.weightx=weightx;
constraints.weighty=weighty;
constraints.fill=fill;
constraints.anchor=anchor;
gbl.setConstraints(component, constraints);
add(component);
}
}