import java.awt.*;
import javax.swing.*;public class TestG{
public static void main(String[] args)
{
ZFrame frameg=new ZFrame();
frameg.setTitle("个人信息调查表");
frameg.setSize(550,478);
frameg.setVisible(true);
}
}class ZFrame extends JFrame
{
public ZFrame(){
ZPanel panelg=new ZPanel();
this.add(panelg);
}
}
class ZPanel extends JPanel
{
public ZPanel(){
JLabel lblName=new JLabel("姓名:");
JTextField txtName=new JTextField(5);
JLabel sexName=new JLabel("性别:");
JTextField sex1Name=new JTextField(5);
JTextArea txtArea=new JTextArea(25,50);
JButton btnOk=new JButton("OK");
JCheckBox chkLove=new JCheckBox("登山");
txtName.setHorizontalAlignment(JTextField.RIGHT);
this.add(lblName);
this.add(txtName);
this.add(sexName);
this.add(sex1Name);
this.add(txtArea);
this.add(btnOk);
this.add(chkLove);
//this.setBackground(Color.BLUE);
}
}
import javax.swing.*;public class TestG{
public static void main(String[] args)
{
ZFrame frameg=new ZFrame();
frameg.setTitle("个人信息调查表");
frameg.setSize(550,478);
frameg.setVisible(true);
}
}class ZFrame extends JFrame
{
public ZFrame(){
ZPanel panelg=new ZPanel();
this.add(panelg);
}
}
class ZPanel extends JPanel
{
public ZPanel(){
JLabel lblName=new JLabel("姓名:");
JTextField txtName=new JTextField(5);
JLabel sexName=new JLabel("性别:");
JTextField sex1Name=new JTextField(5);
JTextArea txtArea=new JTextArea(25,50);
JButton btnOk=new JButton("OK");
JCheckBox chkLove=new JCheckBox("登山");
txtName.setHorizontalAlignment(JTextField.RIGHT);
this.add(lblName);
this.add(txtName);
this.add(sexName);
this.add(sex1Name);
this.add(txtArea);
this.add(btnOk);
this.add(chkLove);
//this.setBackground(Color.BLUE);
}
}
构造器里填上this.pack()就可以了。