JFrame und JDialog

Olga1995

Grünschnabel
Hallo zusammen,

Die Aufgabe war es eine Matrize mit zufälligen Zahlen zu initialisieren, dann soll der Benutze mit einem JSpinner eine Zahl zwischen 0-9 auswählen.

In einem 2ten Vektor soll dann angezeigt werden wie viele Zahlen einer Kolonne ihre 1er Stellen größer als diese Zahl haben.

Anschließend soll der Benutzer die Matrize und den Vektor speichern/laden können.

Hat auch alles gut geklappt, meine Frage ist jetzt:

Ich will das der Vektor in einem JDialog angezeigt wird wenn ich auf einen JButton klicke..

Ich hoffe es kann mir einer helfen und danke im voraus.

PHP:
private void muiInitActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        Remplirmat();
        Remplirvect();
    }                                      

    private void muiClearActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        int i,j;
        for(i=0;i<mat.getRowCount();i++)        
            for(j=0;j<mat.getColumnCount();j++)              
                mat.setValueAt(0, i, j);
        for(i=0;i<vect.getColumnCount();i++)
            vect.setValueAt(0, 0, i);
        minVect.setValue(0);
    }                                        

    private void minVectStateChanged(javax.swing.event.ChangeEvent evt) {                                    
        // TODO add your handling code here:
        Remplirvect();
    }                                    

    private void muiSaveActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        int nbr,i,j;
       
        try{
            FileOutputStream foc=new FileOutputStream("fichier.dat");
            DataOutputStream dout=new DataOutputStream(foc);
           
            nbr=(int) minVect.getValue();
            dout.writeInt(nbr);
            for(i=0;i<mat.getRowCount();i++)        
                for(j=0;j<mat.getColumnCount();j++)              
                    dout.writeInt((int)mat.getValueAt(i,j));  
            for(j=0;j<mat.getColumnCount();j++)              
                    dout.writeInt((int)vect.getValueAt(0,j));
        }catch(IOException err){}
    }                                      

    private void muiLoadActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        int nbr,i,j;
             
        try{
            FileInputStream fic=new FileInputStream("fichier.dat");
            DataInputStream din=new DataInputStream(fic);
           
            nbr=din.readInt();
            minVect.setValue(nbr);
            for(i=0;i<mat.getRowCount();i++)        
                for(j=0;j<mat.getColumnCount();j++)              
                    mat.setValueAt(din.readInt(),i,j);  
            for(j=0;j<mat.getColumnCount();j++)              
                    vect.setValueAt(din.readInt(),0,j);
        }catch(IOException err){}
    }                                      

    private void ShowActionPerformed(java.awt.event.ActionEvent evt) {                                    
   
       
Neu dialog = new Neu(this, true); 
dialog.setLocationRelativeTo(this); 
dialog.setVisible(true);

    }                                    

    private void Remplirmat(){
        int i,j;
        Random val=new Random();
             
        for(i=0;i<mat.getRowCount();i++)        
            for(j=0;j<mat.getColumnCount();j++)              
                mat.setValueAt(val.nextInt(89)+10, i, j);                          
    }
   
    private void Remplirvect(){
        int i,j,compteur,y;
        int borne=(int) minVect.getValue();
       
        for(i=0;i<mat.getColumnCount();i++){
            compteur=0;              
            for(j=0;j<mat.getRowCount();j++){
                y=(int) mat.getValueAt(j,i);
                while(y>9){
                    y+=-10;
                }
                if(y>borne){
                    compteur++;    
                }
            }
            vect.setValueAt(compteur,0,i);
        } 
    }
 

Neue Beiträge

Zurück