奶黄包配咸鸭蛋 2019-09-26 11:27 采纳率: 0%
浏览 509

为什么我的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条回答

  • 毕小宝 博客专家认证 2019-09-26 13:49
    关注

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

    CreateWestPanel()
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器