Code java

ilhemo Messages postés 32 Date d'inscription   Statut Membre Dernière intervention   -  
ilhemo Messages postés 32 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
j'ai un code java pour afficher un message d'erreur , mais ce code dans une package qui contien plusieur class.
alors
1-comment fait pour executer ce programme seul ( donner moi le code correcte )? .
2-Quel est le rôle de initcomponents() ?

package ead;

public class ERREUR extends javax.swing.JFrame {

/** Creates new form ERREUR */
public ERREUR() {
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">//GEN-BEGIN:initComponents
private void initComponents() {

jDialog1 = new javax.swing.JDialog();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();

javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
jDialog1.getContentPane().setLayout(jDialog1Layout);
jDialog1Layout.setHorizontalGroup(
jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
jDialog1Layout.setVerticalGroup(
jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Erreur!!");

jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 0, 0));
jLabel2.setText("Attention vous avez marqué un erreur!!");

jLabel3.setFont(new java.awt.Font("Times New Roman", 3, 14)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 0, 0));
jLabel3.setIcon(new javax.swing.ImageIcon("C:\\tf\\GIF's\\32X32\\info.gif")); // NOI18N
jLabel3.setText("Verifier");

jButton1.setIcon(new javax.swing.ImageIcon("C:\\tf\\GIF's\\24X24\\cancel.gif")); // NOI18N
jButton1.setText("Fermer");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

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)
.addGroup(layout.createSequentialGroup()
.addGap(136, 136, 136)
.addComponent(jLabel2))
.addGroup(layout.createSequentialGroup()
.addGap(163, 163, 163)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jLabel3))))
.addContainerGap(210, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:

ERREUR AA=new ERREUR();
this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

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


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JDialog jDialog1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
// End of variables declaration//GEN-END:variables

}



merci d'avnace
A voir également:

3 réponses

Phortitou Messages postés 221 Date d'inscription   Statut Membre Dernière intervention   27
 
Faut un main() pour pouvoir exécuter un programme. Mais j'ai pas trop compris ce que tu voulais faire
0
ilhemo Messages postés 32 Date d'inscription   Statut Membre Dernière intervention  
 
Je veux fair main() à ce programme ,ma question est comment ?
Et aussi une autre question sur le rôle de initComponents();
0
Phortitou Messages postés 221 Date d'inscription   Statut Membre Dernière intervention   27
 
Tu crées un objet erreur dans ton main
main(){
ERREUR a = new ERREUR();
}

et ensuite tu utilises les méthodes de la classe
Ou alors tu ajoutes un main dans la classe ERREUR directement si tu veux tester si telle ou telle partie du programme fonctione.

Pour le initcomponents() je sais pas, peut-etre que comme son nom l'indique il initialise les composants? Je sais pas
0
ilhemo Messages postés 32 Date d'inscription   Statut Membre Dernière intervention  
 
merci
0