用Java语言编写QQ面板
发布网友
发布时间:2022-04-30 03:18
我来回答
共1个回答
热心网友
时间:2023-10-09 11:41
package cn.myself.myproject.FrameProject;import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;import cn.myself.myproject.employeepj.view.common.CenterWindow;
/**
* 程序功能:QQ登陆面板
* 学习内容:GridBagLayout布局方式的学习
* 以GridBagLayout方式布局的容器,其容器中的每个组件必须由一个GridBagConstrains类的实例对象进行大小,位置等约束。
* @author huliu 2009-06-26
* 难题:a.帐号后面是什么框?
* b.图片的相对路径怎么设置?
*/
public class QQRegistBoard extends JFrame{
JPanel p1;
GridBagLayout gb1;
GridBagConstraints gbc1;
JButton btn1,btn2;
JLabel label0,label1,label2,label3,label4,label5;
JTextField text1,text2;
JComboBox box1,box2;
JCheckBox check1,check2;
JList list1;
/**
* 构造方法
*/
public QQRegistBoard(){
super("2009正式版(huliu)");
p1=new JPanel();
gb1=new GridBagLayout();
gbc1=new GridBagConstraints();
p1.setLayout(gb1);//GridBagLayout布局。网袋布局
getContentPane().add(p1); //取得当前容器对象
this.setSize(350,250);
CenterWindow.centerW(this);
Icon icon1 = new ImageIcon("./QQ2.jpg");
// Icon icon1 = new ImageIcon("./QQ.jpg"); //加载图片,当前目录下的QQ.jpg
// Icon icon1 = new ImageIcon("src/cn/mysef/images/QQ1.jpg");
label0=new JLabel(icon1);
label1=new JLabel("帐号:");
label2=new JLabel("注册新帐号");
label3=new JLabel("密码:");
label4=new JLabel("取回密码");
label5=new JLabel("状态:");
text1=new JTextField(10);
text2=new JTextField(10);
String[] str1={"313558851","313857401","690442763"};
box1=new JComboBox(str1);
box1.setEditable(true);//设置ComboBox字段值是否为可编辑
box2=new JComboBox();
check1=new JCheckBox("记住密码",true);
check2=new JCheckBox("自动登录");
btn1=new JButton("设置");
btn2=new JButton("登录");
p1.add(label0,GBC(0,0,3,1,new Insets(5,2,2,4)));//图片
p1.add(label1,GBC(1,0,1,1,new Insets(4,2,2,4)));
p1.add(box1, GBC(1,1,1,1,new Insets(4,2,2,0)));
//p1.add(text2,GBC(1,1,1,1));
p1.add(label2,GBC(1,2,1,1,new Insets(4,2,2,3)));
p1.add(label3,GBC(2,0,1,1,new Insets(4,2,2,3)));
p1.add(text1, GBC(2,1,1,1,new Insets(5,2,2,3)));
p1.add(label4,GBC(2,2,1,1,new Insets(4,2,2,3)));
p1.add(label5,GBC(3,0,1,1,new Insets(4,2,2,3)));
p1.add(check1,GBC(3,1,1,1,new Insets(4,2,2,3)));
p1.add(check2,GBC(3,2,1,1,new Insets(4,2,2,3)));
p1.add(btn1 ,GBC(4,0,1,1,new Insets(4,2,2,3)));
p1.add(btn2 ,GBC(4,2,1,1,new Insets(4,2,2,3)));
}
/**
* GBC方法:功能是设计以GridBagLayout方式布局的容器(如Panel容器对象)内的组件的位置,大小等约束的。
* @param gridy
* @param gridx
* @param gridwidth
* @param gridheight
* @return GridBagStraints实对象
* Insets(int top, int left, int bottom, int right),与其它组件之间距离(上,左,下,右)
*/
public GridBagConstraints GBC(int gridy,int gridx,int gridwidth,int gridheight,Insets insets){
GridBagConstraints gbc1=new GridBagConstraints();
gbc1.gridx=gridx; //列
gbc1.gridy=gridy; //行
gbc1.gridwidth=gridwidth;//宽度
gbc1.gridheight=gridheight; //高度
//insets=new Insets(1,1,1,1);
gbc1.insets=insets;
return gbc1;
}
public static void main(String[] args){
new QQRegistBoard().setVisible(true);
}}