IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JBuilder Java Discussion :

[Débutant][jb8]sous-composant visuel dynamique+ exception


Sujet :

JBuilder Java

  1. #1
    Membre expérimenté

    Homme Profil pro
    Senior Développeur JEE
    Inscrit en
    Avril 2002
    Messages
    795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Senior Développeur JEE
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Points : 1 660
    Points
    1 660
    Par défaut [Débutant][jb8]sous-composant visuel dynamique+ exception
    java.lang.IllegalArgumentException: argument type mismatch new OptionsPanel(this)
    echec lors de la création du sous-composant visuel dynamique optionsPanel en pdg.OptionsPanel(cls) ; création d'un composant rouge à la place
    J'ai cette exception lorsque je crée un panel

    J'ai ma frame principale et je viens y greffer tous mes panels nécessaires
    En utilisant ce code.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    public class Principale extends JFrame {
     OptionsPanel optionsPanel = new OptionsPanel(this);}
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    public class OptionsPanel extends JPanel {
      Principale principale;
      OverlayLayout2 overlayLayout21 = new OverlayLayout2();
     
      public OptionsPanel(Principale p) {
     
        principale = p;
        try {
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }
      void jbInit() throws Exception {
        this.setLayout(overlayLayout21);
        this.setBorder(BorderFactory.createEtchedBorder());
      }
    }
    Je crois que ma conception est mauvaise malgré que cela compile et que mon application se lance.

    Il faut dire que je travaille tout le temps de la même manière mais il me semble que JB n'aime pas cette manière de faire

  2. #2
    Membre éprouvé
    Avatar de request
    Inscrit en
    Novembre 2002
    Messages
    328
    Détails du profil
    Informations forums :
    Inscription : Novembre 2002
    Messages : 328
    Points : 1 248
    Points
    1 248
    Par défaut
    Salut Stessy,

    Bon, j'ai fait le test, cela fonctionne.

    Je m'explique:
    Tous les composants doivent être des "Beans" et donc avec un constructeur sans argument.

    Voici le résultat:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    public class Principale extends JFrame {
      JPanel contentPane;
      OptionsPanel OptionsPanel = new OptionsPanel();
     
      public Principale() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
     
      private void jbInit() throws Exception  {
        OptionsPanel.setPrincipale(this);
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(null);
        this.setSize(new Dimension(400, 300));
        this.setTitle("Titre du cadre");
        OptionsPanel.setBounds(new Rectangle(29, 39, 329, 223));
        contentPane.add(OptionsPanel, null);
      }
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    public class OptionsPanel extends JPanel {
      Principale principale;
      BorderLayout borderLayout1 = new BorderLayout();
      JButton jButton1 = new JButton();
      JTextArea jTextArea1 = new JTextArea();
     
      public OptionsPanel() {
        try {
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }
      void jbInit() throws Exception {
        jButton1.setText("jButton1");
        this.setLayout(borderLayout1);
        jTextArea1.setText("jTextArea1");
        this.add(jButton1, BorderLayout.NORTH);
        this.add(jTextArea1, BorderLayout.CENTER);
      }
      public void setPrincipale(Principale principale) {
        this.principale = principale;
      }
    }
    En design du principal, on voit même le rendu du panel, snif, c'est beau 8)

    J'éspère que cette solution te convient.

  3. #3
    Membre expérimenté

    Homme Profil pro
    Senior Développeur JEE
    Inscrit en
    Avril 2002
    Messages
    795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Senior Développeur JEE
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Points : 1 660
    Points
    1 660
    Par défaut
    Tu sais que je t'aime



    En tout cas ça fonctionne à merveille 8)

    merci

  4. #4
    Membre éprouvé
    Avatar de request
    Inscrit en
    Novembre 2002
    Messages
    328
    Détails du profil
    Informations forums :
    Inscription : Novembre 2002
    Messages : 328
    Points : 1 248
    Points
    1 248
    Par défaut
    Citation Envoyé par Stessy
    Tu sais que je t'aime



    En tout cas ça fonctionne à merveille 8)

    merci
    J'avoue que le résultat ma aussi agréablement surpris.

    Mais ... bon je t'ai déjà dit de ne pas trop en faire sur les forums publiques, cela me gène tériblement

  5. #5
    Membre expérimenté

    Homme Profil pro
    Senior Développeur JEE
    Inscrit en
    Avril 2002
    Messages
    795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Senior Développeur JEE
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Points : 1 660
    Points
    1 660
    Par défaut
    Avertissement : impossible de définir la propriété "principale" pour saisiePanel -- java.lang.IllegalArgumentException: argument type mismatch
    Avertissement : impossible de définir la propriété "principale" pour optionsPanel -- java.lang.IllegalArgumentException: argument type mismatch
    Avertissement : impossible de définir la propriété "principale" pour recherchePanel -- java.lang.IllegalArgumentException: argument type mismatch
    Avertissement : impossible de définir la propriété "principale" pour tablesPanel -- java.lang.IllegalArgumentException: argument type mismatch
    Avertissement : impossible de définir la propriété "principale" pour footerPanel -- java.lang.IllegalArgumentException: argument type mismatch
    Avertissement : impossible de définir la propriété "principale" pour headerPanel -- java.lang.IllegalArgumentException: argument type mismatch
    Avertissement : impossible de définir la propriété "principale" pour boutonsPanel -- java.lang.IllegalArgumentException: argument type mismatch
    lors du passage à l'onglet conception

  6. #6
    Membre éprouvé
    Avatar de request
    Inscrit en
    Novembre 2002
    Messages
    328
    Détails du profil
    Informations forums :
    Inscription : Novembre 2002
    Messages : 328
    Points : 1 248
    Points
    1 248
    Par défaut
    Tu peux me donner le code de tes 2 classes.

  7. #7
    Membre expérimenté

    Homme Profil pro
    Senior Développeur JEE
    Inscrit en
    Avril 2002
    Messages
    795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Senior Développeur JEE
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Points : 1 660
    Points
    1 660
    Par défaut
    Principale

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    package pdg;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
     
    /**
     * <p>Titre : </p>
     * <p>Description : </p>
     * <p>Copyright : Copyright (c) 2003</p>
     * <p>Société : </p>
     * @author non attribuable
     * @version 1.0
     */
     
    public class Principale extends JFrame {
      JPanel contentPane;
      JMenuBar jMenuBar1 = new JMenuBar();
      JMenu jMenuFile = new JMenu();
      JMenuItem jMenuFileExit = new JMenuItem();
      JMenu jMenuHelp = new JMenu();
      JMenuItem jMenuHelpAbout = new JMenuItem();
      JToolBar jToolBar = new JToolBar();
      JButton jButton1 = new JButton();
      JButton jButton2 = new JButton();
      JButton jButton3 = new JButton();
      ImageIcon image1;
      ImageIcon image2;
      ImageIcon image3;
      XYLayout xYLayout1 = new XYLayout();
      BoutonsPanel boutonsPanel = new BoutonsPanel();
      TablesPanel tablesPanel = new TablesPanel();
      OptionsPanel optionsPanel = new OptionsPanel();
      SaisiePanel saisiePanel = new SaisiePanel();
      HeaderPanel headerPanel = new HeaderPanel();
      RecherchePanel recherchePanel = new RecherchePanel();
      FooterPanel footerPanel = new FooterPanel();
     
      //Construire le cadre
      public Principale() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Initialiser le composant
      private void jbInit() throws Exception  {
     
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int screenHeight = screenSize.height;
        int screenWidth = screenSize.width;
        this.setSize(new Dimension(1024,768));
     
     
        image1 = new ImageIcon(pdg.Principale.class.getResource("openFile.png"));
        image2 = new ImageIcon(pdg.Principale.class.getResource("closeFile.png"));
        image3 = new ImageIcon(pdg.Principale.class.getResource("help.png"));
     
        optionsPanel.setPrincipale(this);
        boutonsPanel.setPrincipale(this);
        headerPanel.setPrincipale(this);
        footerPanel.setPrincipale(this);
        tablesPanel.setPrincipale(this);
        saisiePanel.setPrincipale(this);
        recherchePanel.setPrincipale(this);
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(xYLayout1);
       // this.setSize(new Dimension(400, 300));
        this.setTitle("PDG");
        jMenuFile.setText("Fichier");
        jMenuFileExit.setText("Quitter");
        jMenuFileExit.addActionListener(new Principale_jMenuFileExit_ActionAdapter(this));
        jMenuHelp.setText("Aide");
        jMenuHelpAbout.setText("A propos");
        jMenuHelpAbout.addActionListener(new Principale_jMenuHelpAbout_ActionAdapter(this));
        jButton1.setIcon(image1);
        jButton1.setToolTipText("Ouvrir un fichier");
        jButton2.setIcon(image2);
        jButton2.setToolTipText("Fermer le fichier");
        jButton3.setIcon(image3);
        jButton3.setToolTipText("Aide");
        xYLayout1.setWidth(1024);
        xYLayout1.setHeight(768);
        contentPane.setMinimumSize(new Dimension(1024, 768));
        jToolBar.add(jButton1);
        jToolBar.add(jButton2);
        jToolBar.add(jButton3);
        jMenuFile.add(jMenuFileExit);
        jMenuHelp.add(jMenuHelpAbout);
        jMenuBar1.add(jMenuFile);
        jMenuBar1.add(jMenuHelp);
        this.setJMenuBar(jMenuBar1);
        contentPane.add(jToolBar,  new XYConstraints(0, 0, 400, -1));
        contentPane.add(saisiePanel,  new XYConstraints(123, 68, 889, 305));
     
        contentPane.add(optionsPanel, new XYConstraints(11, 197, 109, 175));
        contentPane.add(recherchePanel, new XYConstraints(11, 375, 1002, 30));
        contentPane.add(tablesPanel, new XYConstraints(12, 405, 1002, 279));
        contentPane.add(footerPanel, new XYConstraints(11, 686, 1002, 30));
        contentPane.add(headerPanel,         new XYConstraints(123, 37, 889, 29));
        contentPane.add(boutonsPanel, new XYConstraints(11, 37, 108, 156));
     
      }
      //Opération Fichier | Quitter effectuée
      public void jMenuFileExit_actionPerformed(ActionEvent e) {
        System.exit(0);
      }
      //Opération Aide | A propos effectuée
      public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
        Principale_AboutBox dlg = new Principale_AboutBox(this);
        Dimension dlgSize = dlg.getPreferredSize();
        Dimension frmSize = getSize();
        Point loc = getLocation();
        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
        dlg.setModal(true);
        dlg.pack();
        dlg.show();
      }
      //Supplanté, ainsi nous pouvons sortir quand la fenêtre est fermée
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          jMenuFileExit_actionPerformed(null);
        }
      }
    }
     
    class Principale_jMenuFileExit_ActionAdapter implements ActionListener {
      Principale adaptee;
     
      Principale_jMenuFileExit_ActionAdapter(Principale adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jMenuFileExit_actionPerformed(e);
      }
    }
     
    class Principale_jMenuHelpAbout_ActionAdapter implements ActionListener {
      Principale adaptee;
     
      Principale_jMenuHelpAbout_ActionAdapter(Principale adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jMenuHelpAbout_actionPerformed(e);
      }
    }
    OptionsPanel

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    package pdg;
     
    import java.awt.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
     
    /**
     * <p>Titre : </p>
     * <p>Description : </p>
     * <p>Copyright : Copyright (c) 2003</p>
     * <p>Société : </p>
     * @author non attribuable
     * @version 1.0
     */
     
    public class OptionsPanel extends JPanel {
      Principale principale;
      OverlayLayout2 overlayLayout21 = new OverlayLayout2();
     
      public OptionsPanel() {
     
     
        try {
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }
      void jbInit() throws Exception {
        this.setLayout(overlayLayout21);
        this.setBorder(BorderFactory.createEtchedBorder());
      }
     
      public void setPrincipale(Principale p) {
        this.principale = p;
      }
     
    }

  8. #8
    Membre éprouvé
    Avatar de request
    Inscrit en
    Novembre 2002
    Messages
    328
    Détails du profil
    Informations forums :
    Inscription : Novembre 2002
    Messages : 328
    Points : 1 248
    Points
    1 248
    Par défaut
    En effet même sur mon exemple, il y a des Warnings.
    Pour les éviter, tu peux faire ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
      //Construire le cadre
      public Principale() {
        optionsPanel.setPrincipale(this);
        boutonsPanel.setPrincipale(this);
        headerPanel.setPrincipale(this);
        footerPanel.setPrincipale(this);
        tablesPanel.setPrincipale(this);
        saisiePanel.setPrincipale(this);
        recherchePanel.setPrincipale(this);
     
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
    N'utilises pas le paquet: import com.borland.jbcl.layout.*;
    Il avait été créé à l'époque ou AWT était très primitif. Sun a comblé le retard en ajoutant les layout manquant: le XYLayout peut être remplcé par le null...

    A+

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Création et destruction dynamique de composants visuels
    Par Dr.Gang dans le forum C++Builder
    Réponses: 3
    Dernier message: 16/10/2009, 17h19
  2. Réponses: 5
    Dernier message: 19/02/2007, 15h44
  3. pb avec composant visuel créé dynamiquement
    Par richard038 dans le forum Composants VCL
    Réponses: 9
    Dernier message: 12/08/2005, 09h59
  4. est il possible de serialiser un composant visuel ?
    Par uliss dans le forum C++Builder
    Réponses: 12
    Dernier message: 15/04/2004, 10h22
  5. exploiter un évènement d'un sous composant dans un
    Par bjl dans le forum Composants VCL
    Réponses: 2
    Dernier message: 20/12/2002, 16h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo