为什么我的JFrame已经设置布局了,下面设置却会报错

public class CreatChat {
private static JFrame jf = new JFrame();

/**
 * 
 */
public CreatChat(){
    CreatPanel creatPanel = new CreatPanel();
    jf.setSize(426, 300);
    jf.setLocationRelativeTo(null);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setUndecorated(true);
    jf.setResizable(false);
    BorderLayout border_layout = new BorderLayout();
    jf.setLayout(border_layout);
    JPanel panel1 = creatPanel.CreateNorthPanel(jf);
    jf.add(panel1,BorderLayout.PAGE_START);
    JPanel panel2 = creatPanel.CrateCenterPanel(jf);
    jf.add(panel2,BorderLayout.CENTER);
    JPanel panel3 = creatPanel.CreateWestPanel(jf);
    jf.add(panel3,BorderLayout.LINE_START);
    JPanel panel4 = creatPanel.CrateSouthPanel(jf);
    jf.add(panel4,BorderLayout.PAGE_END);
    JPanel panel5 = creatPanel.CrateEastPanel(jf);
    jf.add(panel5,BorderLayout.LINE_END);
    jf.setVisible(true);
}

}

public class CreatPanel {

/**
 * 
 */
private static final long serialVersionUID = -9049626153916559813L;
private static LoginListener ll = null;

public static JPanel CreateNorthPanel(final JFrame jf){
    JPanel panel = new JPanel();
    panel.setLayout(null);
    panel.setPreferredSize(new Dimension());
    ImageIcon image = new ImageIcon("images/back.jpg");
    JLabel background = new JLabel(image);
    background.setBounds(0, 0, 426, image.getIconHeight());
    panel.add(background);
    JButton out = new JButton(new ImageIcon("images/close_normal.jpg"));
    out.setBounds(403, 0, 26, 26);
    out.setRolloverIcon(new ImageIcon("images/close_hover.jpg"));
    out.setBorderPainted(false);
    out.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            jf.dispose();
        }
    });
    panel.add(out);
    return panel;
}
public static JPanel CreateWestPanel(){
    JPanel panel = new JPanel();
    panel.setLayout(null);
    panel.setPreferredSize(new Dimension(130,0));
    ImageIcon image = new ImageIcon("images/qq.jpg");
    JLabel background = new JLabel(image);
    background.setBounds(0, 0, 120, 110);
    panel.add(background);
    return panel;
}
public static JPanel CrateCenterPanel(JFrame jf){
    JPanel panel = new JPanel();
    String str[] = {"123456789","456789123","789456123"};
    JComboBox jcoCenter = new JComboBox(str);//为什么不能使用JComboBox<Object>
    panel.add(jcoCenter);
    jcoCenter.setEditable(true);
    jcoCenter.setBounds(0, 15, 175, 30);
    jcoCenter.setFont(new Font("Calibri",0,13));
    JPasswordField jpaCenter = new JPasswordField();
    jpaCenter.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));
    jpaCenter.setBounds(0, 44, 175, 30);
    jpaCenter.setPreferredSize(new Dimension(185,25));
    panel.add(jpaCenter);
    ImageIcon image = new ImageIcon("image/keyboard.jgp");
    JButton jbu = new JButton(image);
    jbu.setPreferredSize(new Dimension(22,20));
    jbu.setBorderPainted(false);
    jpaCenter.add(jbu);
    JCheckBox jch1 = new JCheckBox("记住密码");
    jch1.setFocusPainted(false);
    jch1.setFont(new Font("宋体",0,13));
    jch1.setBounds(0, 85, 80, 20);
    panel.add(jch1);
    JCheckBox jch2 = new JCheckBox("自动登录");
    jch2.setFocusPainted(false);
    jch2.setFont(new Font("宋体",0,12));
    jch2.setBounds(100, 85, 80, 20);
    ll = new LoginListener(jcoCenter, jpaCenter, jf);
    panel.add(jch2);
    return panel;
}
public static JPanel CrateEastPanel(){
    JPanel panel = new JPanel();
    panel.setLayout(null);
    panel.setPreferredSize(new Dimension(100,0));
    JLabel regeist = new JLabel("注册账号");
    regeist.setForeground(new Color(100,149,238));
    regeist.setBounds(0, 13, 60, 30);
    regeist.setFont(new Font("宋体",0,12));
    JLabel regetpwd = new JLabel("找回密码");
    regetpwd.setForeground(new Color(100,149,238));
    regetpwd.setBounds(0, 13, 60, 30);
    regetpwd.setFont(new Font("宋体",0,12));
    panel.add(regetpwd);
    panel.add(regeist);
    return panel;
}
public static JPanel CrateSouthPanel(){
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(0,51));
panel.setLayout(null);
JButton jble = new JButton(new ImageIcon("images/single_normal.jgp"));
jble.setPreferredSize(new Dimension(40,40));
jble.setFocusPainted(false);
jble.setRolloverIcon(new ImageIcon("images/single_down.jpg"));
jble.setBorderPainted(false);
jble.setContentAreaFilled(false);
jble.setBounds(0, 10, 40, 40);
jble.setToolTipText("多账号登录");
ImageIcon image = new ImageIcon("images/login_normal.jpg");
JButton jb = new JButton("登      录",image);
jb.setFont(new Font("宋体",0,13));
jb.setBounds(130, 0, 175, 40);
jb.setHorizontalTextPosition(SwingConstants.CENTER);
jb.setFocusPainted(false);
jb.setContentAreaFilled(false);
jb.setBorderPainted(false);
jb.setRolloverIcon(new ImageIcon("images/login_hover.jpg"));
jb.addActionListener(ll);
JButton jbri = new JButton(new ImageIcon("images/right_normal.jpg"));
jbri.setBounds(380, 10, 40, 40);
jbri.setFocusPainted(false);
jbri.setBorderPainted(false);
jbri.setContentAreaFilled(false);
jbri.setRolloverIcon(new ImageIcon("images/right_hover.jpg"));
jbri.setToolTipText("二维码登录");
panel.add(jble);
panel.add(jb);
panel.add(jbri);
panel.add(panel);
return panel;
}

}

为什么我的JFrame已经设置布局了,下面设置却会报错

1个回答

因为你的方法定义的是无参数的,而你调用的时候却入了一个 jf 参数。
修正为:

CreateWestPanel()
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!