Les Jframes de Swing

linzo85 Messages postés 4 Date d'inscription vendredi 30 avril 2010 Statut Membre Dernière intervention 13 octobre 2010 - 13 oct. 2010 à 18:36
maryouma21 Messages postés 1 Date d'inscription jeudi 29 avril 2010 Statut Membre Dernière intervention 23 octobre 2010 - 23 oct. 2010 à 02:09
Bonjour tout le mon,
j'ai un probleme qui m'empeche de dormir ces temp-ci et j veux votre aide svp.

je suis sur un projet que je dois réaliser en java swing.
je travaille avec netbeans j'ai créé une clas frame ou jé mi un menubar u menu nommé securité qui contien un menuitem nommé mot de passe, deux panel jpanel1 et jpanel2
jé créé une autre classe panel nommé changer()
je dois apres avoir cliquer sur le menuitem mot de passe, remplacer jpanel2 par panel qui est une instance de changer avec le netbeans
mé sa ne marche pas.
voici les deux classe.

(pour le le frame)
public class Menu extends javax.swing.JFrame {


/** Creates new form Menu */
public Menu() {
/* pa=new JPanel();*/

initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jToolBar1 = new javax.swing.JToolBar();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
jMenu2 = new javax.swing.JMenu();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
securiteM = new javax.swing.JMenu();
passMI = new javax.swing.JMenuItem();
jSeparator3 = new javax.swing.JPopupMenu.Separator();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jToolBar1.setRollover(true);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 248, Short.MAX_VALUE)
);

jLabel1.setText("helllllllllllllllllllllllllloooooooooo");

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(43, 43, 43)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(118, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(47, 47, 47)
.addComponent(jLabel1)
.addContainerGap(187, Short.MAX_VALUE))
);

jMenu1.setText("File");
jMenu1.add(jSeparator1);

jMenuBar1.add(jMenu1);

jMenu2.setText("Edit");
jMenu2.add(jSeparator2);

jMenuBar1.add(jMenu2);

securiteM.setText("Security");

passMI.setText("changer password");
passMI.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
passMIActionPerformed(evt);
}
});
securiteM.add(passMI);
securiteM.add(jSeparator3);

jMenuBar1.add(securiteM);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);

pack();
}// </editor-fold>

private void passMIActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getActionCommand().equals("changer password")){
JOptionPane.showMessageDialog(null, "acessssssssss");
ChangerP panel=new ChangerP();
this.getContentPane().remove(jPanel2);
jPanel2=panel;
this.getContentPane().add(jPanel2);
jPanel2.revalidate();
}
}

/**
* @param args the command line arguments
*/

// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JPopupMenu.Separator jSeparator3;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JMenuItem passMI;
private javax.swing.JMenu securiteM;
// End of variables declaration

}

pour le panel



public class ChangerP extends javax.swing.JPanel {

/** Creates new form ChangerP */
public ChangerP() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

loginL = new javax.swing.JLabel();
passL = new javax.swing.JLabel();
loginT = new javax.swing.JTextField();
passT = new javax.swing.JTextField();
validerB = new javax.swing.JButton();
annulerB = new javax.swing.JButton();

loginL.setText("Login");

passL.setText("Password");

validerB.setText("valider");
validerB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
validerBActionPerformed(evt);
}
});

annulerB.setText("annuler");
annulerB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
annulerBActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(passL)
.addComponent(loginL))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(loginT, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
.addComponent(passT, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(126, 126, 126)
.addComponent(validerB)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(annulerB)))
.addGap(394, 394, 394))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(loginL)
.addComponent(loginT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(passL)
.addComponent(passT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(validerB)
.addComponent(annulerB))
.addContainerGap(445, Short.MAX_VALUE))
);
}// </editor-fold>

private void validerBActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==validerB){
String log=loginT.getText();
String newPass=passT.getText();
Conect co=new Conect();
co.setServer("10.10.32.79");
try{
co.connection(co.getServer());
co.changerPassword(log, newPass);
}catch(Exception e){
e.printStackTrace();

}
}
}

private void annulerBActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==annulerB){
}
}


// Variables declaration - do not modify
private javax.swing.JButton annulerB;
private javax.swing.JLabel loginL;
private javax.swing.JTextField loginT;
private javax.swing.JLabel passL;
private javax.swing.JTextField passT;
private javax.swing.JButton validerB;
// End of variables declaration

}

1 réponse

maryouma21 Messages postés 1 Date d'inscription jeudi 29 avril 2010 Statut Membre Dernière intervention 23 octobre 2010
23 oct. 2010 à 02:09
salut linzo81 G le meme probleme, sauf que moi je travaille sur eclipse, G trois panels et trois menuItems, je veux quand j'appuie sur un menuItem le panel correspondant apparait dans la fenêtre.
Je sais plus comment faire
Heeeeeeeeeelp.
0
Rejoignez-nous