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

AWT/Swing Java Discussion :

Gestion des Listeners avec EventHandler : ça fonctionne pas


Sujet :

AWT/Swing Java

  1. #1
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2007
    Messages
    198
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2007
    Messages : 198
    Points : 76
    Points
    76
    Par défaut Gestion des Listeners avec EventHandler : ça fonctionne pas
    Salut à tous,
    je suis entrain de travailler sur une petite application avec swing.
    je cherche à gérer les événements de mon application. en cherchant sur le web j'ai trouvé l'article suivant Simplifier l'écriture des listeners Java avec EventHandler sur developpez.net
    j'ai essayé d'appliquer ce que me convient dans mon apllication mais rien ne fonctionne. Alors le voilà ce que j'ai fait.
    la classe ToolBarPane: c'est la classe dont je construit un toolbar personnalisé
    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
    package com.jam.views;
     
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Event;
    import java.awt.FlowLayout;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Paint;
    import java.awt.Rectangle;
     
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import com.jam.business.CallPanesService;
    import com.jam.templates.BeanFactoryTemp;
    import com.jam.templates.ItemPane;
     
    import java.awt.ComponentOrientation;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.beans.EventHandler;
     
     
    @SuppressWarnings("serial")
    public class ToolBarPane extends JPanel{
     
    	private ItemPane openItem = null;
    	private ItemPane trsItem = null;
    	private ItemPane importItem = null;
    	private ItemPane exportItem = null;
     
    	ContainerPane cp = new ContainerPane(983, 584);
     
    	public ToolBarPane(int w, int h){
     
    		setSize(w, h);
    		initialize();
    	}
    	/**
             * This method initializes this
             * 
             */
    	private void initialize(){
     
    		setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    		add(getOpenItem(), FlowLayout.LEFT);
    		add(getAddTaskItem(), FlowLayout.LEFT);
    		add(getStructureItem(), FlowLayout.LEFT);
    		add(getTrsItem(), FlowLayout.LEFT);
    		add(getImportItem(), FlowLayout.LEFT);		
    		add(getExportItem(), FlowLayout.LEFT);
    		add(getEmailItem(), FlowLayout.LEFT);
    		add(getAddChatItem(), FlowLayout.LEFT);
    		add(getDiaryItem(), FlowLayout.LEFT);
    		add(getCalendarItem(), FlowLayout.LEFT);
    		add(getAlertItem(), FlowLayout.LEFT);
    		add(getNoteBookItem(), FlowLayout.LEFT);
    		add(getCalculatorItem(), FlowLayout.LEFT);
    		add(getWebSiteItem(), FlowLayout.LEFT);
    		add(getSearchItem(), FlowLayout.LEFT);
    		add(getStatisticItem(), FlowLayout.LEFT);
    		add(getConfigItem(), FlowLayout.LEFT);
     
    	}
     
    	/**
             * This method initializes openItem     
             *      
             * @return javax.swing.JPanel   
             */
    	public ItemPane getOpenItem() {
    		if (openItem == null) {
    			openItem = new ItemPane("assets/new.png", "Nouveau");
    			openItem.setName("openItem");
    			openItem.addMouseListener(EventHandler.create(MouseListener.class, cp, "addSMPane"));
    		}
    		return openItem;
    	}
     
    	/**
             * This method initializes trsItem      
             *      
             * @return javax.swing.JPanel   
             */
    	private ItemPane getTrsItem() {
    		if (trsItem == null) {
    			trsItem = new ItemPane("assets/budget.png","Encaissements" );
    		}
    		return trsItem;
    	}
     
    	/**
             * This method initializes importItem   
             *      
             * @return javax.swing.JPanel   
             */
    	private ItemPane getImportItem() {
    		if (importItem == null) {
    			importItem = new ItemPane("assets/import.png", "Import");
    			importItem.setSize(70, 50);
    		}
    		return importItem;
    	}
     
    	/**
             * This method initializes exportItem   
             *      
             * @return javax.swing.JPanel   
             */
    	private ItemPane getExportItem() {
    		if (exportItem == null) {
    			exportItem = new ItemPane("assets/export.png", "Export");
    		}
    		return exportItem;
    	}
     
     
    }
    Lorsque je clique sur un bouton du toolbar je veux apparaitre l'interface qui convient à ce bouton qui est définit dans une autre classe ContainerPane.
    c'est dans cette classe et via cette méthode que je veux switcher entre les interfaces à afficher lorsque je clique sur un bouton du toolbar.
    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
    package com.jam.views;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Paint;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
     
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    import com.jam.business.CallPanesService;
    import com.jam.templates.BeanFactoryTemp;
    import com.jam.templates.OvalPanel;
     
    public class ContainerPane extends OvalPanel{
     
    	private OvalPanel welcomePane = null;
    	private OvalPanel switchPane  =  null;
    	private JLabel welcomeLbl = null;
    	SyndicatManagerPane smp = null;
     
    	public ContainerPane(){}
     
    	public ContainerPane(int w, int h) {
    		super(w, h);
    		//initialize();
     
    	}
    	public ContainerPane(int w, int h, Dimension d) {
    		super(w, h, d);
    		initialize();
    	}
     
    	/**
             * This method initializes this
             * 
             */
    	public void initialize() {
            setLayout(new BorderLayout());
            add(getWelcomePane(), BorderLayout.NORTH);
            add(getSwitchPane(), BorderLayout.CENTER);	
     
    	}
     
     
    	/**
             * This method initializes welcomeLbl   
             *      
             * @return javax.swing.JPanel   
             */
    	private JLabel getWelcomeLbl() {
    		if (welcomeLbl == null) {
    			welcomeLbl = new JLabel("Bienvenue au Syndicat ");
    			welcomeLbl.setFont(new Font("Calibri", Font.PLAIN, 13));
     
    		}
    		return welcomeLbl;
    	}
     
    	public void addSMPane(){
    		smp = new SyndicatManagerPane(getSwitchPane().getWidth(), getSwitchPane().getHeight()); 
    		getSwitchPane().add(smp);
    	}
    	/**
             * This method initializes menuPane     
             *      
             * @return javax.swing.JPanel   
             */
    	public OvalPanel getSwitchPane() {
    		if (switchPane == null) {
    			switchPane =  new OvalPanel(10, 10, new Dimension(this.getWidth(), this.getHeight()));
     
    		}
    		return switchPane;
    	}
     
     
    	/**
             * This method initializes syndicatView 
             *      
             * @return javax.swing.JPanel   
             */
    	public OvalPanel getWelcomePane() {
    		if (welcomePane == null) {
    			welcomePane = new OvalPanel(3, 3, new Dimension(this.getWidth(), 0));
    			welcomePane.add(getWelcomeLbl(), BorderLayout.CENTER);
     
    		}
    		return welcomePane;
    	}		
    }
    désolé si j'ai trop écrit
    mais vraiment il y a plus qu'un mois que je galère avec les événements, à chaque fois j'essaye un exemple et ça marche parce que je construit tout dans une seule classe. Mais dans mon cas je fais appel à des classes( des classes imbriqués).
    merci d'avance

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    dans le code que tu donne, vu que tu utilise un MouseListener, tous les event souris vont déclencher les addSMPane, je suis à peu près sur que ce n'est pas ce que tu veux.

    Aussi, je vois que tu déclare ContainerPane comme étant un nouveau ContainerPane, mais tu n'en fait rien (tu ne l'affiche pas). Donc tout changement que tu fais dedans, rien ne sera visible.


    Comment par faire des System.println dans ta méthode addSMPane pour savoir si le problème est que l'action n'est pas déclenchée ou si elle n'est simplement pas visible.

  3. #3
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2007
    Messages
    198
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2007
    Messages : 198
    Points : 76
    Points
    76
    Par défaut
    Bonjour,
    merci tchize_ pour votre réponse.
    Aussi, je vois que tu déclare ContainerPane comme étant un nouveau ContainerPane, mais tu n'en fait rien (tu ne l'affiche pas). Donc tout changement que tu fais dedans, rien ne sera visible.
    oui parceque je fais appel à addSMPane (définit dans la classe ContainerPane) dans la classe ToolBarPane(c'est là où je géré les cliques sur les boutons du toolbar).
    je sais pas s'il y a une façon plus meilleur de le faire.

    Comment par faire des System.println dans ta méthode addSMPane pour savoir si le problème est que l'action n'est pas déclenchée ou si elle n'est simplement pas visible.
    j'ai essayé d'afficher un message dans la méthode, ça marche.
    merci

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par j_esti Voir le message

    oui parceque je fais appel à addSMPane (définit dans la classe ContainerPane) dans la classe ToolBarPane(c'est là où je géré les cliques sur les boutons du toolbar).
    Tu dois faire appel sur l'instance de ContainerPane qui est actuellement affichée dans ta fenêtre, pas sur une nouvelle que tu crée comme ça dans ToolBarPane et qui n'est pas affichée.

    Bref, pour que tes changement que tu fais dans le ContainerPane soient visible, il faut que ce dernier soit affiché quelque part

  5. #5
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2007
    Messages
    198
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2007
    Messages : 198
    Points : 76
    Points
    76
    Par défaut
    Tu dois faire appel sur l'instance de ContainerPane qui est actuellement affichée dans ta fenêtre, pas sur une nouvelle que tu crée comme ça dans ToolBarPane et qui n'est pas affichée.
    le voilà mon structure ci-joint (structure.png), peut être c'est compliqué
    Le containerPane est appelé dans ManagerPane. Comment je dois faire appel à l'instance (container) dans le ToolBarPane.

    Bref, pour que tes changement que tu fais dans le ContainerPane soient visible, il faut que ce dernier soit affiché quelque part
    ci-joint l'interface de mon application, et donc je pense que ContainerPane est visible.

    merci bien
    Images attachées Images attachées   

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Tu as actuellement 2 ContainerPane. Un visible, instancée par ManagerPane, je suppose, et un invisible, instancé par ToolbarPane et c'est celui là que tu modifier.

    Tu dois passer à ton ToolbarPane l'instance de ContainerPane que tu veux utiliser. par exemple en le passant au constructeur.

  7. #7
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2007
    Messages
    198
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2007
    Messages : 198
    Points : 76
    Points
    76
    Par défaut
    Tu dois passer à ton ToolbarPane l'instance de ContainerPane que tu veux utiliser. par exemple en le passant au constructeur.
    d'après ce que j'ai compris, c'est que je je vais instancier ContainerPane dans ToolBarPane parce que ToolBarPane c'est une classe à part.

    par exemple en le passant au constructeur
    est lorsque je vais faire le EventHandler dans ToolBarPane
    openItem.addMouseListener(EventHandler.create(MouseListener.class, qu'est ce je dois mettre ici, "addSMPane"));

    Désolé si mes questions vous paraissent stupide mais juste je veux comprendre.

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Tu dois mettre cp, comme tu l'a fait, ce n'est pas un problème.

    Le problème c'est la ligne

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ContainerPane cp = new ContainerPane(983, 584);
    Dans ton toolbar. A priori ca n'a pas sa place là. Donc je suppose que, ailleurs, tu a aussi une ligne similaire qui instance une deuxième containerpane et qui, lui, est visible.

  9. #9
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2007
    Messages
    198
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2007
    Messages : 198
    Points : 76
    Points
    76
    Par défaut
    désolé si mal compris,dans mon ToolBarPane je mets cp et alors je dois l'instancier dans cette classe.
    la seule instance que je fais appel c'est dans ManagerPane selon la structure dont je l'ai mise comme pièce jointe.
    le voilà la classe ManagerPane:
    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
    package com.jam.views;
     
    import java.awt.Dimension;
    import javax.swing.JPanel;
     
     
    import java.awt.BorderLayout;
    import java.awt.event.MouseListener;
     
    @SuppressWarnings("serial")
    public class ManagerPane extends JPanel {
     
    	private TriPane triPane = null;
    	private ContainerPane container = null;
    	SyndicatManagerPane smp = null;
     
     
    	public ManagerPane(){
    		super();
    		initialize();
    	}
    	/**
             * This method initializes this
             * 
             */
    	private void initialize() {
            setLayout(new BorderLayout());
            setSize(1083, 584);
            add(getTriPane(), BorderLayout.WEST);
            add(getContainerPane(), BorderLayout.CENTER);
     
    	}
     
    	/*public void addSMPane(){
    		smp = new SyndicatManagerPane(container.getSwitchPane().getWidth(), container.getSwitchPane().getHeight()); 
    		getContainerPane().getSwitchPane().add(smp);
    	}*/
     
    	/**
             * This method initializes container    
             *      
             * @return javax.swing.JPanel   
             */
    	public ContainerPane getContainerPane() {
    		if (container == null) {
    			container = new ContainerPane(10, 10, new Dimension(this.getWidth() - 100, this.getHeight()));
    			smp = new SyndicatManagerPane(container.getSwitchPane().getWidth(), container.getSwitchPane().getHeight()); 
    			container.getSwitchPane().add(smp);
     
    		}
    		return container;
    	}
     
    	/**
             * This method initializes container    
             *      
             * @return javax.swing.JPanel   
             */
    	private TriPane getTriPane() {
    		if (triPane == null) {
    			triPane = new TriPane(10, 10, new Dimension(100, this.getHeight()));
    		}
    		return triPane;
    	}
     
    }
    merci

  10. #10
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par j_esti Voir le message
    désolé si mal compris,dans mon ToolBarPane je mets cp et alors je dois l'instancier dans cette classe.
    la seule instance que je fais appel c'est dans ManagerPane selon la structure dont je l'ai mise comme pièce jointe.
    Non, déjà tu as 2 instance dans ton cas. Ensuite, ce n'est pas parce que le ToolBarPane a besoin d'un référence à ContainerPane qu'il dois la créer lui même. Au contraire, il a besoin de cette référence, la question que tu dois te poser, c'est comment la lui passer. Le plus simple est par le constructeur dans ton cas:
    Dans toolbarPane:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    	ContainerPane cp;
    	public ToolBarPane(int w, int h, ContainerPane cp){
     
    		this.cp = cp;
    		setSize(w, h);
    		initialize();
    	}
    	public ContainerPane(int w, int h, Dimension d, ContainerPane cp) {
    		this.cp = cp;
    		super(w, h, d);
    		initialize();
    	}
    Et dans le code appelant, bien entendu, tu lui passe ce containerPane, que tu as déjà instancié dans ManagerPane.

  11. #11
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2007
    Messages
    198
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2007
    Messages : 198
    Points : 76
    Points
    76
    Par défaut
    j'ai fais les modifications que vous m'avez mentionné.
    j'avais encore de la confusion
    si je vais faire
    ContainerPane cp;
    public ToolBarPane(int w, int h, ContainerPane cp){

    this.cp = cp;
    setSize(w, h);
    initialize();
    }
    alors selon la structure des appels dans mon application:
    ça c'est la classe main SyndicatMain
    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
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    /**
     * 
     */
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.ComponentOrientation;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Insets;
    import java.awt.Paint;
    import java.awt.Rectangle;
    import java.awt.Toolkit;
    import java.awt.event.MouseListener;
    import java.beans.EventHandler;
    
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    
    
    import com.jam.commons.*;
    import com.jam.views.ManagerPane;
    import com.jam.views.ToolBarPane;
    
    
    
    /**
     * @author jamila
     *
     */
    public class SyndicatMain extends JFrame{
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	/**
    	 * @param args
    	 */
    
    	
    		private JPanel mainPane = null;
    		private ManagerPane managerPane = null;
    		private ToolBarPane toolBarPane = null;
    		private JMenu info = null;
    		private JMenu file = null;
    		private JMenu resident = null;
    		private JMenu transaction = null;
    		private JMenu assembly = null;
    		
    		private JMenu rent = null;
    		private JMenu financial = null;
    		private JMenu maintenance = null;
    		private JMenu historic = null;
    		private JMenu report = null;
    		private JMenu configuration = null;
    		private JMenuBar mainMenuBar = null;
    		
    		/**
    		 * This method initializes 
    		 * 
    		 */
    		public  SyndicatMain() {
    			super();
    			initialize();
    			//com.sun.awt.AWTUtilities.setWindowOpacity(this,0.9f);
    		}
    		
    		/**
    		 * This method initializes this
    		 * 
    		 */
    		private void initialize() {
    		    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    			setSize(dim.width/2 + 400 ,dim.height/2 + 250);
    			setLocation(dim.width/2 - getWidth()/2, dim.height/2 - getHeight()/2);
    		    setContentPane(getMainPane());
    		    setBackground(new Color(252, 252, 252));
    		    setJMenuBar(getMainMenuBar());
    		    setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    		    setTitle("Gestion du Syndicat");
    		    
    				
    		}
    		
    		/**
    		 * This method initializes mainPanel	
    		 * 	
    		 * @return javax.swing.JPanel	
    		 */
    		private JPanel getMainPane() {
    			if (mainPane == null) {
    				mainPane = new JPanel();
    				mainPane.setSize(this.getWidth(), this.getHeight());
    				mainPane.setLayout(new BorderLayout());
    				mainPane.add(getToolBarPane(), BorderLayout.NORTH);
    				mainPane.add(getManagerPane(), BorderLayout.CENTER);
    				}
    			return mainPane;
    		}
    		
    		
    		/**
    		 * This method initializes managerPane	
    		 * 	
    		 * @return javax.swing.JPanel	
    		 */
    		public ManagerPane getManagerPane() {
    			if (managerPane == null) {
    				managerPane = new ManagerPane();
    				managerPane.setSize(mainPane.getWidth(), mainPane.getHeight()- 50);
    								
    			}
    			return managerPane;
    		}
    		
    		/**
    		 * This method initializes managerPane	
    		 * 	
    		 * @return javax.swing.JPanel	
    		 */
    		private ToolBarPane getToolBarPane() {
    			if (toolBarPane == null) {
    				toolBarPane = new ToolBarPane(this.getWidth(), 50, getManagerPane().getContainerPane());
    				// lorsque je dois instancier toolBarPane je vais faire appel à une instance de ContainerPane 
    			}
    			return toolBarPane;
    		}
    
    		/**
    		 * This method initializes file	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getFile() {
    			if (file == null) {
    				file = new JMenu("file");
    				file.setText("Fichier");
    				file.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return file;
    		}
    		
    		/**
    		 * This method initializes file	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getInfo() {
    			if (info == null) {
    				info = new JMenu("info");
    				info.setText("Info");
    				info.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return info;
    		}
    		
    		/**
    		 * This method initializes Resident	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getResident() {
    			if (resident == null) {
    				resident = new JMenu("resident");
    				resident.setText("Résidents");
    				resident.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return resident;
    		}
    
    		/**
    		 * This method initializes Assembly	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getAssembly() {
    			if (assembly == null) {
    				assembly = new JMenu("assembly");
    				assembly.setText("Assemblé");
    				assembly.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return assembly;
    		}
    		/**
    		 * This method initializes Transaction	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getTransaction() {
    			if (transaction == null) {
    				transaction = new JMenu("transaction");
    				transaction.setText("Transactions");
    				transaction.setFont(new Font("Calibri", Font.PLAIN, 13));
    				
    			}
    			return transaction;
    		}
    		/**
    		 * This method initializes rent	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getRent() {
    			if (rent == null) {
    				rent = new JMenu("rent");
    				rent.setText("Location");
    				rent.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return rent;
    		}
    		
    		
    		/**
    		 * This method initializes Maintenance	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getMaintenance() {
    			if (maintenance == null) {
    				maintenance = new JMenu("maintenance");
    				maintenance.setText("Maintenance");
    				maintenance.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return maintenance;
    		}
    		
    		
    		
    		/**
    		 * This method initializes Financial state	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getFinancial() {
    			if (financial == null) {
    				financial = new JMenu("fianacial");
    				financial.setText("États Financiers");
    				financial.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return financial;
    		}
    		
    		/**
    		 * This method initializes historic	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getHistoric() {
    			if (historic == null) {
    				historic = new JMenu("historic");
    				historic.setText("Historique");
    				historic.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return historic;
    		}
    		
    		/**
    		 * This method initializes reports	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getReport() {
    			if (report == null) {
    				report = new JMenu("report");
    				report.setText("Rapports");
    				report.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return report;
    		}
    		
    		/**
    		 * This method initializes configuration	
    		 * 	
    		 * @return javax.swing.JMenu	
    		 */
    		private JMenu getConfiguration() {
    			if (configuration == null) {
    				configuration = new JMenu("configuration");
    				configuration.setText("Configuration");
    				configuration.setFont(new Font("Calibri", Font.PLAIN, 13));
    			}
    			return configuration;
    		}
    		
    		
    		/**
    		 * This method initializes mainMenuBar1	
    		 * 	
    		 * @return javax.swing.JMenuBar	
    		 */
    		private JMenuBar getMainMenuBar() {
    			if (mainMenuBar == null) {
    				mainMenuBar = new JMenuBarTemp();
    				mainMenuBar.setMargin(new Insets(10,5,10,5));
    				mainMenuBar.setForeground(new Color(188, 207, 243));
    				mainMenuBar.add(getFile());
    				mainMenuBar.add(getInfo());
    				mainMenuBar.add(getAssembly());
    				mainMenuBar.add(getResident());
    				mainMenuBar.add(getRent());
    				mainMenuBar.add(getTransaction());
    				mainMenuBar.add(getFinancial());
    				mainMenuBar.add(getMaintenance());
    				mainMenuBar.add(getHistoric());
    				mainMenuBar.add(getReport());
    				mainMenuBar.add(getConfiguration());
    			}
    			return mainMenuBar;
    		}
    		
    
    		public static void main(String[] args) {
    			SyndicatMain sm = new SyndicatMain();
    			sm.setVisible(true);
    			
    		}
    		
    		}  //  @jve:decl-index=0:visual-constraint="10,10"
    
    class JMenuBarTemp extends JMenuBar{
    	
    	private Image photoFr ;
    	private Image photoEn;
    	private Image photoTn;
    	private Image helpIcon = null;
    	
    	public JMenuBarTemp() {
    		super();
    		
    	}
    	
    	/**
    	 * This method initializes helpItem	
    	 * 	
    	 * @return javax.swing.JPanel	
    	 */
    	private Image getHelpItem() {
    		if (helpIcon == null) {
    			helpIcon = getToolkit().getImage("assets/help.png");
    		}
    		return helpIcon;
    	}
    	
    	/*
    	 * 
     	 * This method have to be changed to reduce the number of codeline's
     	 *
     	 */
    	protected void paintComponent(Graphics g){
         	
         	super.paintComponents(g);
         	photoFr = getToolkit().getImage("assets/fr.jpg");
         	photoEn = getToolkit().getImage("assets/en.jpg");
         	photoTn = getToolkit().getImage("assets/tn.jpg");
         	
         	Rectangle bounds = getBounds();
         	Graphics2D _g = (Graphics2D) g;
            Paint gradientPaint = new GradientPaint(0, bounds.y, new Color(252, 252, 252), 0, bounds.y + bounds.width, 
            		new Color(197 , 204, 204));
            _g.setPaint(gradientPaint);
            //g.fillRect(0, 0, this.getWidth() - 66, this.getHeight());
            g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 5, 5);
            g.drawImage(photoFr, this.getWidth() - 22, 4, this);
         	g.drawImage(photoEn, this.getWidth() - 43, 4, this);
         	g.drawImage(photoTn, this.getWidth() - 64, 4, this);
         	g.drawImage(getHelpItem(), this.getX()+ 765, 0, this);
    	 }
    	
    }
    la classe ManagerPane
    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
    package com.jam.views;
     
    import java.awt.Dimension;
    import javax.swing.JPanel;
     
     
    import java.awt.BorderLayout;
    import java.awt.event.MouseListener;
     
    @SuppressWarnings("serial")
    public class ManagerPane extends JPanel {
     
    	private TriPane triPane = null;
    	ContainerPane container = null;
     
    	public ManagerPane(){
    		super();
    		initialize();
    	}
    	/**
             * This method initializes this
             * 
             */
    	private void initialize() {
            setLayout(new BorderLayout());
            setSize(1083, 584);
            add(getTriPane(), BorderLayout.WEST);
            add(getContainerPane(), BorderLayout.CENTER);
     
    	}
     
     
     
    	/**
             * This method initializes container    
             *      
             * @return javax.swing.JPanel   
             */
    	public ContainerPane getContainerPane() {
    		if (container == null) {
    			container = new ContainerPane(10, 10, new Dimension(this.getWidth() - 100, this.getHeight()));
     
     
    		}
    		return container;
    	}
     
    	/**
             * This method initializes container    
             *      
             * @return javax.swing.JPanel   
             */
    	private TriPane getTriPane() {
    		if (triPane == null) {
    			triPane = new TriPane(10, 10, new Dimension(100, this.getHeight()));
    		}
    		return triPane;
    	}
     
    }
    le ContainerPane
    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
    package com.jam.views;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Paint;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
     
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    import com.jam.business.CallPanesService;
    import com.jam.commons.BeanFactoryTemp;
    import com.jam.commons.OvalPanel;
     
    public class ContainerPane extends OvalPanel{
     
    	private OvalPanel welcomePane = null;
    	private OvalPanel switchPane  =  null;
    	private JLabel welcomeLbl = null;
    	SyndicatManagerPane smp;
     
    	public ContainerPane(){}
     
    	public ContainerPane(int w, int h) {
    		super(w, h);		
    	}
    	public ContainerPane(int w, int h, Dimension d) {
    		super(w, h, d);
    		initialize();
    	}
     
    	public void addSMPane(){
    		smp = new SyndicatManagerPane(getSwitchPane().getWidth(), getSwitchPane().getHeight()); 
    		getSwitchPane().add(smp);
    		System.out.println("hello");
    	}
    	/**
             * This method initializes this
             * 
             */
    	public void initialize() {
            setLayout(new BorderLayout());
            add(getWelcomePane(), BorderLayout.NORTH);
            add(getSwitchPane(), BorderLayout.CENTER);	
     
    	}
     
     
    	/**
             * This method initializes welcomeLbl   
             *      
             * @return javax.swing.JPanel   
             */
    	private JLabel getWelcomeLbl() {
    		if (welcomeLbl == null) {
    			welcomeLbl = new JLabel("Bienvenue au Syndicat ");
    			welcomeLbl.setFont(new Font("Calibri", Font.PLAIN, 13));
     
    		}
    		return welcomeLbl;
    	}
     
    	/**
             * This method initializes menuPane     
             *      
             * @return javax.swing.JPanel   
             */
    	public OvalPanel getSwitchPane() {
    		if (switchPane == null) {
    			switchPane =  new OvalPanel(10, 10, new Dimension(this.getWidth(), this.getHeight()));
     
    		}
    		return switchPane;
    	}
     
     
    	/**
             * This method initializes syndicatView 
             *      
             * @return javax.swing.JPanel   
             */
    	public OvalPanel getWelcomePane() {
    		if (welcomePane == null) {
    			welcomePane = new OvalPanel(3, 3, new Dimension(this.getWidth(), 0));
    			welcomePane.add(getWelcomeLbl(), BorderLayout.CENTER);
     
    		}
    		return welcomePane;
    	}		
    }
    merci

  12. #12
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Août 2007
    Messages
    198
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2007
    Messages : 198
    Points : 76
    Points
    76
    Par défaut
    merci bien tchize_ pour votre aide, ça marche bien maintenant

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

Discussions similaires

  1. [AJAX] Réception des données avec POST
    Par Akim13 dans le forum AJAX
    Réponses: 18
    Dernier message: 20/12/2012, 13h19
  2. Simplifier l'écriture des listeners avec EventHandler
    Par le y@m's dans le forum Général Java
    Réponses: 25
    Dernier message: 05/07/2012, 15h50
  3. [MySQL] Suppression avec des case a cocher ne fonctionne pas
    Par runcafre91 dans le forum PHP & Base de données
    Réponses: 12
    Dernier message: 13/02/2010, 18h02
  4. [AC-2003] Envoi des touches ^P avec SendKeys ne fonctionne pas?
    Par electrosat03 dans le forum VBA Access
    Réponses: 5
    Dernier message: 27/06/2009, 15h25

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