Besoin d'aide : De JButton à JTextField

cs_javalang Messages postés 18 Date d'inscription dimanche 29 mars 2009 Statut Membre Dernière intervention 15 août 2009 - 4 avril 2009 à 00:42
dmk04 Messages postés 206 Date d'inscription samedi 29 octobre 2005 Statut Membre Dernière intervention 7 mars 2012 - 6 avril 2009 à 09:10
Salut !
Besoin urgent d'aide.
Quand je clique sur les boutons, je voudrais que les lettres qui sont écrites dessus se reportent dans des JTextFields.
Les JTextFields sont dans une collection et les boutons sont générés dans un tableau avec des lettres.
Voici mon code de JButtons suivi du code des JTexFields.

Ceci peut paraitre bête, mais je suis novice

=====JBUTTONS=====
    private ArrayList<String> GenLettres() {
        final int nbVoyelles = 3;
        final int nbConsonnes = 3;
        final int nbAutres = 2;

        ArrayList<String> lettres = new ArrayList<String>();

        Random random = new Random(System.currentTimeMillis());

        for (int i = 0; i < nbVoyelles; ++i) {
            char voyelle = VOYELLES.charAt(random.nextInt(VOYELLES.length()));
            lettres.add("" + voyelle);
        }
        for (int j = 0; j < nbConsonnes; ++j) {
            char consonnes = CONSONNES.charAt(random.nextInt(CONSONNES.length()));
            lettres.add("" + consonnes);
        }
        for (int k = 0; k < nbAutres; ++k) {
            char autre = AUTRES.charAt(random.nextInt(AUTRES.length()));
            lettres.add("" + autre);
        }
        Collections.shuffle(lettres);
        System.out.println(lettres);
       
        return lettres;
    }
+++++++++++++++++++++

===JTEXTFIELDS=====
    public Grille() {
        layout = new GridBagLayout();
        setLayout(layout);
        contraintes = new GridBagConstraints();

        txt1 = new EnumMap<Operation, JTextField>(Operation.class);
        txt2 = new EnumMap<Operation, JTextField>(Operation.class);
        txt3 = new EnumMap<Operation, JTextField>(Operation.class);
        txt4 = new EnumMap<Operation, JTextField>(Operation.class);
        txt5 = new EnumMap<Operation, JTextField>(Operation.class);     
       
        for (Operation op : Operation.values()) {

            JTextField txt = new JTextField(" ");
            txt.setFont(new Font(txt.getFont().getName(), Font.BOLD, 30));
            txt.setPreferredSize(new Dimension(60, 60));
            txt.setHorizontalAlignment(JTextField.CENTER);
            txt.setEditable(false);
            txt1.put(op, txt);

            txt = new JTextField("  ");
            txt.setHorizontalAlignment(JTextField.CENTER);
            txt.setFont(new Font(txt.getFont().getName(), Font.BOLD, 30));
            txt.setPreferredSize(new Dimension(60, 60));
            txt2.put(op, txt);
            txt.setEditable(false);

            txt = new JTextField("  ");
            txt.setHorizontalAlignment(JTextField.CENTER);
            txt.setFont(new Font(txt.getFont().getName(), Font.BOLD, 30));
            txt.setPreferredSize(new Dimension(60, 60));
            txt3.put(op, txt);
            txt.setEditable(false);

            txt = new JTextField("  ");
            txt.setHorizontalAlignment(JTextField.CENTER);
            txt.setFont(new Font(txt.getFont().getName(), Font.BOLD, 30));
            txt.setPreferredSize(new Dimension(60, 60));
            txt4.put(op, txt);
            txt.setEditable(false);

            txt = new JTextField("  ");
            txt.setHorizontalAlignment(JTextField.CENTER);
            txt.setFont(new Font(txt.getFont().getName(), Font.BOLD, 30));
            txt.setPreferredSize(new Dimension(60, 60));
            txt5.put(op, txt);
            txt.setEditable(false);
        }

        contraintes.fill = GridBagConstraints.BOTH;
        int r = 1;
        for (Operation op : Operation.values()) {
            addComp(txt1.get(op), r, 1, 1, 1);
            addComp(txt2.get(op), r, 2, 1, 1);
            addComp(txt3.get(op), r, 3, 1, 1);
            addComp(txt4.get(op), r, 4, 1, 1);
            addComp(txt5.get(op), r, 5, 1, 1);
            ++r;
        }
    }
+++++++++++++++++++++

MERCI D'AVANCE

1 réponse

dmk04 Messages postés 206 Date d'inscription samedi 29 octobre 2005 Statut Membre Dernière intervention 7 mars 2012
6 avril 2009 à 09:10
0
Rejoignez-nous