【问题标题】:No suitable constructor found for JDateChooser(string,string,char)没有为 JDateChooser(string,string,char) 找到合适的构造函数
【发布时间】:2020-10-22 17:10:09
【问题描述】:

我是 java 新手,我尝试修复一些朋友遇到问题的代码,但我遇到了一个让我有点困惑的错误,我得到的错误是:

no suitable constructor found for JDateChooser(String,String,char)
    constructor JDateChooser.JDateChooser() is not applicable
      (actual and formal argument lists differ in length)
    constructor JDateChooser.JDateChooser(ImageIcon) is not applicable
      (actual and formal argument lists differ in length)
    constructor JDateChooser.JDateChooser(boolean) is not applicable
      (actual and formal argument lists differ in length)
    constructor JDateChooser.JDateChooser(String,boolean) is not applicable
      (actual and formal argument lists differ in length)
    constructor JDateChooser.JDateChooser(JCalendar) is not applicable
      (actual and formal argument lists differ in length)
    constructor JDateChooser.JDateChooser(JCalendar,String,boolean,ImageIcon) is not applicable
      (actual and formal argument lists differ in lengt...

我尝试为其添加构造函数,但我对 java 的了解不足以修复它
这是代码示例。 错误出现在代码的最后两行

        public void actionPerformed(ActionEvent e) {
            Reservation = new JFrame();
            Reservation.setAlwaysOnTop(true);
            Reservation.setTitle("R\u00E9servation");
            Reservation.getContentPane().setLayout(null);
            
            
            JPanel clientPan = new JPanel();
            clientPan.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 0), 1, true), "Client", TitledBorder.LEADING, TitledBorder.TOP, null, null));
            clientPan.setBounds(10, 11, 424, 211);
            Reservation.getContentPane().add(clientPan);
            clientPan.setLayout(null);
            
            JPanel selectClientPan = new JPanel();
            selectClientPan.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 0), 1, true), "S\u00E9lection Client", TitledBorder.LEADING, TitledBorder.TOP, null, null));
            selectClientPan.setBounds(215, 21, 177, 154);
            clientPan.add(selectClientPan);
            selectClientPan.setLayout(null);
            
            
            final ComplexSwingX list = new ComplexSwingX(hotel);
            list.setBounds(10, 29, 157, 114);           
            selectClientPan.add(list);
            
            
            JPanel createClientPan = new JPanel();
            createClientPan.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 0), 1, true), "Cr\u00E9ation Client", TitledBorder.LEADING, TitledBorder.TOP, null, null));
            createClientPan.setBounds(10, 21, 195, 154);
            clientPan.add(createClientPan);
            createClientPan.setLayout(null);
            
            JLabel lblNom = new JLabel("Nom : ");
            lblNom.setBounds(10, 24, 60, 14);
            createClientPan.add(lblNom);
            
            JLabel lblAdresse = new JLabel("Adresse : ");
            lblAdresse.setBounds(10, 124, 60, 14);
            createClientPan.add(lblAdresse);
            
            JLabel lblPrnom = new JLabel("Pr\u00E9nom");
            lblPrnom.setBounds(10, 74, 60, 14);
            createClientPan.add(lblPrnom);
            
            clientName = new JTextField();
            clientName.setBounds(99, 21, 86, 20);
            createClientPan.add(clientName);
            clientName.setColumns(10);
            
            clientFirstname = new JTextField();
            clientFirstname.setBounds(99, 71, 86, 20);
            createClientPan.add(clientFirstname);
            clientFirstname.setColumns(10);
            
            clientAddress = new JTextField();
            clientAddress.setBounds(99, 118, 86, 20);
            createClientPan.add(clientAddress);
            clientAddress.setColumns(10);
            
            final JPanel reservationPan = new JPanel();
            reservationPan.setVisible(false);
            reservationPan.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 0), 1, true), "R\u00E9servation", TitledBorder.LEADING, TitledBorder.TOP, null, null));
            reservationPan.setBounds(69, 230, 323, 194);
        
            final JDateChooser D1 = new JDateChooser("dd/MM/yyyy", "####/##/####", '_');
            final JDateChooser D2 = new JDateChooser("dd/MM/yyyy", "####/##/####", '_');

【问题讨论】:

  • 错误消息告诉您有可用于 JDateChooser 的构造函数,但它们都与您尝试发送的内容不匹配。在每种情况下,您都发送两个字符串和一个 char,但没有一个构造函数是为这 3 个参数设计的。我意识到您是 Java 新手。什么信息导致您尝试使用这些参数创建 JDateChooser?请查看 JDateChooser 的文档或源代码。

标签: java jdatechooser jcalendar


【解决方案1】:

您的问题正是错误消息告诉您的。这些行:

final JDateChooser D1 = new JDateChooser("dd/MM/yyyy", "####/##/####", '_');
final JDateChooser D2 = new JDateChooser("dd/MM/yyyy", "####/##/####", '_');

是无效语法,因为JDateChooser 类没有将两个字符串和一个字符作为参数的构造函数。错误消息列出了该类确实包含的所有构造函数。如果你想创建一个JDateChooser,你必须使用它提供的构造函数之一。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    • 2015-09-07
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多