Récupération d'une matrice.
barney_vegeta
Messages postés
21
Statut
Membre
-
barney_vegeta Messages postés 21 Statut Membre -
barney_vegeta Messages postés 21 Statut Membre -
Bonjour,
J'ai un package qui contient plusieurs classes, parmi ces classes il y'a la classe 1 est une fenêtre JDialog qui reçoit des données entrées par un utilisateur et fait des opérations sur ces données afin de calculer une certaine matrice, et c'est cette matrice que je veux récupérer dans la classe 2 afin de l'afficher dans une JFrame.
voilà le code de la classe 1
et tout ce que je veut récupérer de cette classe c'est la matrice "élémentsConfusion"
Le code de la classe 2 est le suivant:
cette classe est une fenêtre que je veux qu'elle m'affiche la matrice "élémentsConfusion" calculée après ce que l'utilisateur entre ses données dans la première classe.
Merci
J'ai un package qui contient plusieurs classes, parmi ces classes il y'a la classe 1 est une fenêtre JDialog qui reçoit des données entrées par un utilisateur et fait des opérations sur ces données afin de calculer une certaine matrice, et c'est cette matrice que je veux récupérer dans la classe 2 afin de l'afficher dans une JFrame.
voilà le code de la classe 1
public class dialog_gauss extends javax.swing.JDialog {
/**
* Creates new form dialog_gauss
*/
public dialog_gauss(java.awt.Frame parent, boolean modal) {
super(parent, modal);
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() {
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jLabel1.setText("veuillez saisir les parmètres de la loi gauss:");
jTextField7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField7ActionPerformed(evt);
}
});
jLabel2.setText("Seuil:");
jLabel3.setText("M1:");
jLabel4.setText("M2:");
jLabel5.setText("Moyenne:");
jLabel6.setText("Ecarttype");
jLabel7.setText("Nbpoints:");
jButton1.setText("Quitter");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton2.setText("Suivant>");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Résultat");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(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()
.addContainerGap(29, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jLabel5))
.addGroup(layout.createSequentialGroup()
.addGap(168, 168, 168)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE)
.addGap(9, 9, 9))))
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel7)
.addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)
.addComponent(jTextField6)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton3)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(36, 36, 36))))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7))
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)))
);
pack();
}// </editor-fold>
private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
String Moy1 , Moy2 , ecarty1, ecarty2, npointlignecolonne1, npointlignecolonne2, Seuil;
int nbpoints_g1, nbpoints_g2;
Moy1 = jTextField1.getText();
Moy2= jTextField2.getText();
ecarty1 = jTextField3.getText();
ecarty2 = jTextField4.getText();
npointlignecolonne1= jTextField5.getText();
npointlignecolonne2 = jTextField6.getText();
Seuil = jTextField7.getText();
//Convertion en int
nbpoints_g1= Integer.parseInt(npointlignecolonne1);
nbpoints_g2 = Integer.parseInt( npointlignecolonne2);
//convertion en double
double moy1, moy2, ecartype1, ecartype2, seuil;
moy1 = Double.parseDouble(Moy1 );
moy2= Double.parseDouble(Moy2);
ecartype1 = Double.parseDouble(ecarty1);
ecartype2= Double.parseDouble(ecarty2);
seuil= Double.parseDouble(Seuil);
// convertion en double qui manque
Matrice_gauss rr = new Matrice_gauss( nbpoints_g1, nbpoints_g1, moy1, ecartype1 );
Matrice_gauss tt = new Matrice_gauss(nbpoints_g2, nbpoints_g2, moy2, ecartype2);
int iterationA = 0;
for (int co = 0; co <= nbpoints_g1 - 1; co++) {
for (int con = 0; con <= nbpoints_g1 - 1; con++) {
if (rr.donnees[co][con] < seuil) {
iterationA++;
}
}
}
int iterationB = 0;
for (int co = 0; co <= nbpoints_g2 - 1; co++) {
for (int con = 0; con <= nbpoints_g2 - 1; con++) {
if (tt.donnees[co][con] > seuil) {
iterationB++;
}
}
}
double[][] élémentsConfusion = {{iterationA, nbpoints_g1 * nbpoints_g1 - iterationA}, {nbpoints_g2 * nbpoints_g2 - iterationB, iterationB}};
Matrice_gauss Confusion = new Matrice_gauss(élémentsConfusion);
Confusion.afficherMatrice(Confusion);
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
Affichage1 ff=new Affichage1();
ff.setVisible(true);
this.dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(dialog_gauss.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(dialog_gauss.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(dialog_gauss.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(dialog_gauss.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the dialog
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
dialog_gauss dialog = new dialog_gauss(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
// End of variables declaration
}
et tout ce que je veut récupérer de cette classe c'est la matrice "élémentsConfusion"
Le code de la classe 2 est le suivant:
public class Affichage1 extends javax.swing.JFrame {
/**
* Creates new form Affichage1
*/
public Affichage1() {
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() {
jTextField1 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextField1.setText(" Matrice de Confusion ");
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null,null},
{null,null}
},
new String [] {
"Classe 1", "Classe 2"
}
));
jScrollPane1.setViewportView(jTable1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(84, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(82, 82, 82))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(97, 97, 97))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(56, 56, 56)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(108, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Affichage1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Affichage1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Affichage1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Affichage1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Affichage1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
cette classe est une fenêtre que je veux qu'elle m'affiche la matrice "élémentsConfusion" calculée après ce que l'utilisateur entre ses données dans la première classe.
Merci
A voir également:
- Récupération d'une matrice.
- Récupération de déchets - Guide
- Comment recuperer une video sur youtube - Guide
- Recuperer une conversation whatsapp supprimée - Guide
- Convertisseur récupération de texte - Guide
- Adresse mail de recuperation c'est quoi - Guide
1 réponse
Ça sent la génération automatique de NetBeans tout ça (beurk !)
Tu as déclaré double[][] élémentsConfusion dans jButton2MouseClicked, si tu veux le récupérer ailleurs, tu devrais faire la déclaration comme un champs de la classe dialog_gauss, et ajouter une méthode get pour pouvoir l'utiliser dans Affichage1.
Cependant il faudra faire le lien entre tes deux fenêtres, de sorte par exemple que Affichage1 soit créée en lui passant en paramètre la fenêtre dialog_gauss.
Tu as déclaré double[][] élémentsConfusion dans jButton2MouseClicked, si tu veux le récupérer ailleurs, tu devrais faire la déclaration comme un champs de la classe dialog_gauss, et ajouter une méthode get pour pouvoir l'utiliser dans Affichage1.
Cependant il faudra faire le lien entre tes deux fenêtres, de sorte par exemple que Affichage1 soit créée en lui passant en paramètre la fenêtre dialog_gauss.
public class dialog_gauss ...
{
private double[][] élémentsConfusion = null;
public double[][] getElementConfusion()
{
if (élémentsConfusion==null)
throw new IllegalStateException("l'appel à get doit avoir lieu après l'initialisation");
else
return élémentsConfusion;
}
}
// ...
élémentsConfusion = new double[][] {{iterationA, nbpoints_g1 * nbpoints_g1 - iterationA}, {nbpoints_g2 * nbpoints_g2 - iterationB, iterationB}};
// ...
public class Affichage1
{
private final dialog_gauss dg;
public Affichage1(dialog_gauss dg)
{
this.dg = dg;
initComponents();
}
// ...
double[][] tab = dg.getElementConfusion();
Par contre comme je l'ai mis, "dg" est initialisée dans le constructeur de Affichage1 :
public Affichage1(dialog_gauss dg) { this.dg = dg; initComponents(); }Comme je l'ai fait, on devrait avoir dans le main :
dialog_gauss dialogue = new dialog_gauss(parent, modal); Affichage1 affichage = new Affichage1(dialogue);Comme ça, on sait où l'on doit chercher la matrice lorsque l'on en a besoin...
Si tu mets double[][] tab = dg.getElementConfusion(); dans la main, tu vas avoir une IllegalStateException car le jButton2 n'aura pas encore été cliqué !
sinon pour
dialog_gauss dialogue = new dialog_gauss(parent, modal);
Affichage1 affichage = new Affichage1(dialogue);
lorsque je les mets après "private void jButton3MouseClicked(java.awt.event.MouseEvent evt) { " ça m'affiche plusieurs erreurs, parent et modal ne sont pas public, mais lorsque j'ai fait ce changement
dialog_gauss dialogue = new dialog_gauss(new javax.swing.JFrame(), true);
ça a compilé....
c'est bon le changement que j'ai fais ?? et ou est ce que je dois déclarer double[][] tab = dg.getElementConfusion(); ??
et aussi dans la deuxième classe Affichage1, il me faut un paramètre pour le constructeur Affichage1 de type dialog_gauss (ici exactement new Affichage1().setVisible(true))