我要达到像http://bbs.bc-cn.net/showimgpage.asp?BoardID=8&filename=2007-8/2007826030161949.jpg中的样子,可总是有问题。我用的是网格包。我也不知道那里出问题了。怪怪的,希望有经验的兄弟帮忙看下。顺便告诉我些知识那更好。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Register
{
private JPanel panel;
private GridBagConstraints gc;
private JTextField userNumber;
private JTextField userNikeName;
private JTextField password;
private JTextField name;
private JTextField age;
public Register()
{
userNumber=new JTextField(15);
userNikeName=new JTextField(20);
password=new JTextField(20);
name=new JTextField(10);
age=new JTextField(8);
JFrame frame1=new JFrame("J-QQ用户注册");
frame1.show(true);
panel=new JPanel(new GridBagLayout());
gc=new GridBagConstraints(); gc.fill=GridBagConstraints.VERTICAL;
addComponent(new JLabel("用户号码:"),0,0,3,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(userNumber,0,1,4,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(new JLabel("用户昵称:"),2,0,3,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(userNikeName,2,1,4,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(new JLabel("用户口令:"),4,0,3,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(password,4,1,4,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(new JLabel("姓名:"),6,0,2,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(name,6,1,3,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(new JLabel("年龄:"),6,2,2,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(age,6,3,2,1);
frame1.setSize(415,500);
frame1.add(panel);
}
public void addComponent(Component c,int row,int col,int nrow,int ncol)
{
gc.gridx = col;
gc.gridy = row;
gc.gridwidth = ncol;
gc.gridheight = nrow;
panel.add(c,gc);
}
public static void main(String[] args)
{
Register register=new Register();
}}[upload=jpg]UploadFile/2007-8/2007826030161949.jpg[/upload]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Register
{
private JPanel panel;
private GridBagConstraints gc;
private JTextField userNumber;
private JTextField userNikeName;
private JTextField password;
private JTextField name;
private JTextField age;
public Register()
{
userNumber=new JTextField(15);
userNikeName=new JTextField(20);
password=new JTextField(20);
name=new JTextField(10);
age=new JTextField(8);
JFrame frame1=new JFrame("J-QQ用户注册");
frame1.show(true);
panel=new JPanel(new GridBagLayout());
gc=new GridBagConstraints(); gc.fill=GridBagConstraints.VERTICAL;
addComponent(new JLabel("用户号码:"),0,0,3,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(userNumber,0,1,4,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(new JLabel("用户昵称:"),2,0,3,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(userNikeName,2,1,4,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(new JLabel("用户口令:"),4,0,3,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(password,4,1,4,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(new JLabel("姓名:"),6,0,2,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(name,6,1,3,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(new JLabel("年龄:"),6,2,2,1);
gc.fill=GridBagConstraints.HORIZONTAL;
addComponent(age,6,3,2,1);
frame1.setSize(415,500);
frame1.add(panel);
}
public void addComponent(Component c,int row,int col,int nrow,int ncol)
{
gc.gridx = col;
gc.gridy = row;
gc.gridwidth = ncol;
gc.gridheight = nrow;
panel.add(c,gc);
}
public static void main(String[] args)
{
Register register=new Register();
}}[upload=jpg]UploadFile/2007-8/2007826030161949.jpg[/upload]
用绝对定位算了