A obj=new B; 的语句是成立的. 至于构造器我不太清楚JPanel panel=new JPanel(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridwidth=1;
gbc.gridheight=1;
gbc.gridx=0; // 定义横坐标位置(大约值)
gbc.gridy=0; // 定义纵坐标位置(大约值)
gbc.fill=GridBagConstraints.HORIZONTAL; // 表示让组件横向填充
                                        // BOTH: 横纵双向填充
                                        // NONE: 双向不填充
                                        // VERTICAL: 纵向填充gbc.weightx=0.0; // 0.0 表示组建将不随窗体变化而变化
gbc.weighty=0.0;panel.add(new JButton("Button 1"), gbc); // 注意gbc不要忘记gbc.gridx++;
// gbc.gridy++; or gbc.gridy=1; // 自己试试吧...
// gbc.gridwidth=2;
gbc.weightx=1.0;
panel.add(new JButton("Button 2"), gbc);以上仅供参考.