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

Java Discussion :

Interface Graphique Java


Sujet :

Java

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Août 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2012
    Messages : 3
    Points : 1
    Points
    1
    Par défaut Interface Graphique Java
    Bonjour,

    Je m'exerce actuellement sur les interfaces graphique en Java.

    J'aimerai créer un bouton et faire en sorte que lorsque je clique sur celui-ci un autre menu apparaît dans le même cadre : comme par exemple dans les menus de jeu où lorsqu'on clique sur le bouton option par exemple la liste des options apparaît dans le même cadre avec un bouton retour afin de revenir au menu précédent car jusqu'à présent j'arrive à faire cela seulement en ouvrant une nouveau fenêtre au dessus du cadre de menu.

    Pourriez-vous me donner un exemple de code faisant cela? sa m'aiderai beaucoup..

  2. #2
    Membre éprouvé
    Inscrit en
    Mars 2006
    Messages
    848
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Mars 2006
    Messages : 848
    Points : 1 078
    Points
    1 078
    Par défaut
    Bonjour,

    L'idée est de définir tes composants MenuPrincipal et SousMenu.

    Tu mets ton composant MenuPrincipal dans le ContentPane de ta fenêtre (par exemple). Ensuite, lorsque tu cliques sur le bouton menant au sous-menu, tu remplace le contenu du ContentPane (= MenuPrincipal) par SousMenu.

    Tu peux aussi t'intéresser au CardLayout, c'est une solution assez similaire.

  3. #3
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Août 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2012
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    D'accord je te remercie de ta réponse
    Mais pourrais tu me donner un exemple codé car je suis vraiment débutant au niveau des interfaces graphique et un exemple tout simple avec un bouton à cliqué et l'apparition du menu suivant une fois le clique effectué m'aiderai grandement

  4. #4
    Membre éprouvé
    Inscrit en
    Mars 2006
    Messages
    848
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Mars 2006
    Messages : 848
    Points : 1 078
    Points
    1 078
    Par défaut
    Le tuto Sun/Oracle me paraît très bien: http://docs.oracle.com/javase/tutori...yout/card.html.

    Seule différence avec ce que tu veux faire : c'est une combobox au lieu d'un bouton, mais l'essentiel y est présenté.

  5. #5
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Août 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2012
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    D'accord j'ai essayé ce code :

    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
    /*
     * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     *   - Redistributions of source code must retain the above copyright
     *     notice, this list of conditions and the following disclaimer.
     *
     *   - Redistributions in binary form must reproduce the above copyright
     *     notice, this list of conditions and the following disclaimer in the
     *     documentation and/or other materials provided with the distribution.
     *
     *   - Neither the name of Oracle or the names of its
     *     contributors may be used to endorse or promote products derived
     *     from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
     
    package layout;
     
    /*
     * CardLayoutDemo.java
     *
     */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class CardLayoutDemo implements ItemListener {
        JPanel cards; //a panel that uses CardLayout
        final static String BUTTONPANEL = "Card with JButtons";
        final static String TEXTPANEL = "Card with JTextField";
     
        public void addComponentToPane(Container pane) {
            //Put the JComboBox in a JPanel to get a nicer look.
            JPanel comboBoxPane = new JPanel(); //use FlowLayout
            String comboBoxItems[] = { BUTTONPANEL, TEXTPANEL };
            JComboBox cb = new JComboBox(comboBoxItems);
            cb.setEditable(false);
            cb.addItemListener(this);
            comboBoxPane.add(cb);
     
            //Create the "cards".
            JPanel card1 = new JPanel();
            card1.add(new JButton("Button 1"));
            card1.add(new JButton("Button 2"));
            card1.add(new JButton("Button 3"));
     
            JPanel card2 = new JPanel();
            card2.add(new JTextField("TextField", 20));
     
            //Create the panel that contains the "cards".
            cards = new JPanel(new CardLayout());
            cards.add(card1, BUTTONPANEL);
            cards.add(card2, TEXTPANEL);
     
            pane.add(comboBoxPane, BorderLayout.PAGE_START);
            pane.add(cards, BorderLayout.CENTER);
        }
     
        public void itemStateChanged(ItemEvent evt) {
            CardLayout cl = (CardLayout)(cards.getLayout());
            cl.show(cards, (String)evt.getItem());
        }
     
        /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event dispatch thread.
         */
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("CardLayoutDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            //Create and set up the content pane.
            CardLayoutDemo demo = new CardLayoutDemo();
            demo.addComponentToPane(frame.getContentPane());
     
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        }
     
        public static void main(String[] args) {
            /* Use an appropriate Look and Feel */
            try {
                //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
            } catch (UnsupportedLookAndFeelException ex) {
                ex.printStackTrace();
            } catch (IllegalAccessException ex) {
                ex.printStackTrace();
            } catch (InstantiationException ex) {
                ex.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
            /* Turn off metal's use of bold fonts */
            UIManager.put("swing.boldMetal", Boolean.FALSE);
     
            //Schedule a job for the event dispatch thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }

    Mais le problème c'est que lorsque je clique sur l'un des boutons rien ne se passe
    Et un problème survient notamment au niveau du package layout

  6. #6
    Modérateur

    Avatar de Robin56
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juin 2009
    Messages
    5 297
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Juin 2009
    Messages : 5 297
    Points : 13 670
    Points
    13 670
    Par défaut
    Citation Envoyé par Losc365 Voir le message
    Mais le problème c'est que lorsque je clique sur l'un des boutons rien ne se passe
    Et un problème survient notamment au niveau du package layout
    En même temps, ça dépend de comment tu l'utilises ?
    Responsable Java de Developpez.com (Twitter et Facebook)
    Besoin d'un article/tutoriel/cours sur Java, consulter la page cours
    N'hésitez pas à consulter la FAQ Java et à poser vos questions sur les forums d'entraide Java
    --------
    Architecte Solution
    LinkedIn : https://www.linkedin.com/in/nicolascaudard/

Discussions similaires

  1. affichage d'un CV dans une interface graphique JAVA
    Par midoscofield dans le forum Documents
    Réponses: 2
    Dernier message: 11/05/2009, 15h05
  2. Interface graphique java
    Par clubiste012 dans le forum Débuter
    Réponses: 3
    Dernier message: 11/03/2009, 16h48
  3. matrice interface graphique JAVA
    Par saidoumosta dans le forum Interfaces Graphiques en Java
    Réponses: 1
    Dernier message: 26/01/2009, 11h15
  4. Interface graphique java swing awt toolkit
    Par MaxLaMenaX dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 06/11/2008, 15h39
  5. Composants à utiliser pour une interface graphique Java
    Par nicolas.pied dans le forum Composants
    Réponses: 4
    Dernier message: 28/11/2005, 20h27

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