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

Agents de placement/Fenêtres Java Discussion :

coucou / caché JFrame


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Invité1
    Invité(e)
    Par défaut coucou / caché JFrame
    ,

    J'utilise setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE); pour cacher ma JFrame quand je la ferme mais j'aimerai la faire réapparaître (dans l'état où elle était) en cliquant sur un bouton.
    Quelle méthode faut-il appeler?

    Merci.

  2. #2
    Membre actif
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    179
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2005
    Messages : 179
    Points : 216
    Points
    216
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    myFrame.setVisible(true)
    Fred
    Fred

  3. #3
    Invité1
    Invité(e)
    Par défaut Oui mais!
    En fait mon problème c'est que je ne peux pas appeler cette méthode depuis une autre classe, je m'explique:
    Voici la classe avec la fenêtre que je veux faire disparaître (j'ai enlevé du 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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
     
    public class RoleAdmin extends javax.swing.JFrame {
    private void initComponents() {
            java.awt.GridBagConstraints gridBagConstraints;
            javax.swing.JLabel invitationDescriptionText;
            javax.swing.JLabel invitationPasswordLabel;
            javax.swing.JLabel memberPasswordLabel;
     
            memberTab = new javax.swing.JPanel();
            memberPasswordLabel = new javax.swing.JLabel();
            memberPasswordField = new javax.swing.JPasswordField();
            generateMemberCertButton = new javax.swing.JButton();
            memberAuthenticateButton = new javax.swing.JButton();
            memberGenerateCSRButton = new javax.swing.JButton();
            memberImportCertButton = new javax.swing.JButton();
            memberResignButton = new javax.swing.JButton();
            adminTab = new javax.swing.JPanel();
            adminSignCSRButton = new javax.swing.JButton();
            adminInviteButton = new javax.swing.JButton();
            adminInvitationPasswordLabel = new javax.swing.JLabel();
            adminInvitationPasswordField = new javax.swing.JPasswordField();
            ownerTab = new javax.swing.JPanel();
            ownerSignCSRButton = new javax.swing.JButton();
            ownerPasswordLabel = new javax.swing.JLabel();
            ownerPasswordField = new javax.swing.JPasswordField();
            ownerAuthenticateButton = new javax.swing.JButton();
            ownerResignButton = new javax.swing.JButton();
            invitationTab = new javax.swing.JPanel();
            invitationDescriptionText = new javax.swing.JLabel();
            invitationPasswordLabel = new javax.swing.JLabel();
            invitationPasswordField = new javax.swing.JPasswordField();
            invitationConfirmButton = new javax.swing.JButton();
            keyStorePasswordLabel = new javax.swing.JLabel();
            keyStorePasswordField = new javax.swing.JPasswordField();
            tabs = new javax.swing.JTabbedPane();
            authenticationStatus = new javax.swing.JTextField();
     
            memberTab.setLayout(new java.awt.GridBagLayout());
     
            memberTab.setToolTipText("Actions for Peer Group Members");
            memberTab.setName("Member");
            memberTab.setNextFocusableComponent(adminTab);
            if (membership.getPSEConfig().isInitialized()) {
                tabs.add(memberTab);
            }
            memberPasswordLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
            memberPasswordLabel.setLabelFor(memberPasswordField);
            memberPasswordLabel.setText("Member Password");
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
            gridBagConstraints.insets = new java.awt.Insets(3, 0, 0, 3);
            memberTab.add(memberPasswordLabel, gridBagConstraints);
     
            memberPasswordField.setColumns(16);
            memberPasswordField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    memberPasswordFieldActionPerformed(evt);
                }
            });
            memberPasswordField.addKeyListener(new java.awt.event.KeyAdapter() {
     
                @Override
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    memberPasswordFieldKeyReleasedHandler(evt);
                }
            });
     
            blablablabla
     
            //setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
            setTitle("PSE Peer Group Option");
            addWindowListener(new java.awt.event.WindowAdapter() {
     
                @Override
                public void windowClosed(java.awt.event.WindowEvent evt) {
                    swingUIClosed(evt);
                }
            });
     
            keyStorePasswordLabel.setLabelFor(keyStorePasswordField);
            keyStorePasswordLabel.setText("Key Store Password");
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.ipadx = 3;
            gridBagConstraints.ipady = 3;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
            gridBagConstraints.insets = new java.awt.Insets(5, 3, 1, 0);
            getContentPane().add(keyStorePasswordLabel, gridBagConstraints);
     
            keyStorePasswordField.setColumns(16);
            keyStorePasswordField.setNextFocusableComponent(invitationTab);
            keyStorePasswordField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    keyStorePasswordFieldActionPerformed(evt);
                }
            });
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_END;
            gridBagConstraints.insets = new java.awt.Insets(4, 0, 1, 2);
            getContentPane().add(keyStorePasswordField, gridBagConstraints);
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.ipadx = 3;
            gridBagConstraints.ipady = 3;
            gridBagConstraints.insets = new java.awt.Insets(1, 0, 1, 0);
            getContentPane().add(tabs, gridBagConstraints);
     
            authenticationStatus.setColumns(32);
            authenticationStatus.setEditable(false);
            authenticationStatus.setFont(new java.awt.Font("Dialog", 0, 10));
            authenticationStatus.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED));
            authenticationStatus.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    authenticationStatusActionPerformed(evt);
                }
            });
     
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            gridBagConstraints.ipady = 3;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.LAST_LINE_END;
            gridBagConstraints.insets = new java.awt.Insets(1, 0, 4, 0);
            getContentPane().add(authenticationStatus, gridBagConstraints);
     
            pack();
        }
    }
    Voici mon main (simplifié aussi):
    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
     
    public class Main {
    public Main() throws Exception {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        new app.security.RoleAdmin(npg, ui_pga).setVisible(true);
                    }
                });
    }
     public static void main(String[] args) {
            // Give the Thread we are running on a name for debuggers.
            Thread.currentThread().setName(Main.class.getName() + ".main()");
     
            //We launch first the main GUI (Graphic User Interface)
            SwingUtilities.invokeLater(new Runnable(){
    			public void run(){
    				Interface fenetre = new Interface();
    				fenetre.setVisible(true);
    			}
    		});
     
            try {
                new Main();
            } catch (Throwable all) {
                // Something bad happened, print out the failure and quit.
                System.err.println("Uncaught Throwable in main() :");
                all.printStackTrace(System.err);
                System.exit(1);
            }
        }
    }
    Et c'est dans mon interface fenetre du main qu'il y a un bouton qui est censé faire apparaître cette JFrame:
    Code du bouton qui marche pas!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    public class RoleAction extends AbstractAction {
    	public RoleAction(String texte){
    		super(texte);
    	}
     
    	public void actionPerformed(ActionEvent e) { 
    		app.security.RoleAdmin.setVisible(true);
    	} 
    }
    Et là je sèche, faut-il que la méthode soit statique? Le problème c'est que j'initialise la JFrame et après elle est modifiée, comment ne pas perdre ces modifications?

  4. #4
    Membre actif
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    179
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2005
    Messages : 179
    Points : 216
    Points
    216
    Par défaut
    Bon j'avoue que j'ai pas tout lu en détails, mais déja je vois que dans ton main() tu construis ta frame, la rend visible, mais tu ne stockes sa référence nulle part, or c'est sur cette référence qu'il faudra faire le setVisible() ensuite.

    Du coup, je ne vois que ce que tu fais dans le code du bouton, on dirait l'appel d'une méthode statique ???

    Enfin, je vois que tu as ajouter un listener sur la frame, mais je ne sais pas ce que tu fais dans swingUIClosed(), mais si tu jamais tu fais un dispose() de ta frame, tu ne pourras plus la réafficher.

    Fred
    Fred

  5. #5
    Invité1
    Invité(e)
    Par défaut hey ben voilà
    OUaou la honte! pas assez de café!
    c'était ça merci kwxyz!

Discussions similaires

  1. char * toto = "coucou" cache un new?
    Par Xemame dans le forum Débuter
    Réponses: 9
    Dernier message: 03/02/2011, 14h22
  2. comment caché un jframe à partir d'une classe interne?
    Par glasgow dans le forum Agents de placement/Fenêtres
    Réponses: 3
    Dernier message: 02/08/2009, 10h21
  3. JFrame secondaire auto cachée
    Par Lebas dans le forum Agents de placement/Fenêtres
    Réponses: 1
    Dernier message: 08/01/2008, 15h53
  4. Répertoire caché
    Par KUBITUS dans le forum Delphi
    Réponses: 30
    Dernier message: 13/04/2007, 07h19
  5. Webbrowser : Comment ne pas prendre la page en cache
    Par cedm78 dans le forum Web & réseau
    Réponses: 3
    Dernier message: 30/08/2002, 11h17

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