Eero com mvc

2 respostas
V

Boa noite, estou tentando fazer minha aplicaçao de teste virar uma aplicaçao no modelo MVC, mas nao consigo, tenho erros logo ao utilizar o botao 3 que é de escolher imagem, o inicio da aplicaçao. POR FAVOR me ajudem.

Segue o codigo e o erro:

VIEW
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class Vue extends javax.swing.JFrame implements Observer {

    //CREATION DE L'OBJET DU TYPE FENETRE JFileChooser
    JFileChooser fileChooser = new JFileChooser();
    Modele modele;

    public Vue(Modele modele) {
        initComponents();
        this.modele = modele;
        modele.addObserver(this);
    }

    public Vue() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                initComponents();
                Vue.this.setVisible(true);
            }
        });
    }

    public void addListenersToView(Controleur cont) {
        jButton1.addActionListener(cont);
        jButton2.addActionListener(cont);
        jButton3.addActionListener(cont);
        jButton4.addActionListener(cont);
        jButton5.addActionListener(cont);
        jButton7.addActionListener(cont);
        jButton8.addActionListener(cont);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jButton8 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("Visionneuse");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, 240, 30));

        jButton1.setText("BR");
        /*jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });*/
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 20, -1, -1));

        jButton2.setText("JP");
        jButton2.setMaximumSize(new java.awt.Dimension(45, 23));
        jButton2.setMinimumSize(new java.awt.Dimension(45, 23));
        jButton2.setPreferredSize(new java.awt.Dimension(45, 23));
        /*jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 jButton2ActionPerformed(evt);
            }
        });*/
        jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 20, -1, -1));

        jButton3.setText("CHOISIR REPERTOIRE D'IMAGE");
        /*jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed();
            }
        });*/
        jPanel1.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 100, 290, 43));

        jButton4.setText("MODIFIER LE NOM D'IMAGE");
        jButton4.setEnabled(false);
        /*jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });*/
        jPanel1.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 200, 290, 42));

        jLabel2.setText("Regarder l'Image:");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 60, -1, -1));
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 120, 490, 320));

        jLabel4.setText("Mots Clés:");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 280, 60, -1));
        jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 270, 240, 30));

        jButton5.setText("Adicioner");
        jButton5.setEnabled(false);
        /*jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });*/
        jPanel1.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 320, 90, -1));

        jButton6.setText("Modifier");
        jButton6.setEnabled(false);
        jPanel1.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 320, 100, -1));

        jButton7.setText("Chercher");
        /*jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });*/
        jPanel1.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 320, 100, -1));

        jTextField2.setEnabled(false);
        jTextField2.setName("JTextField2"); // NOI18N
        jPanel1.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 80, 490, 30));
        jPanel1.add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 170, 290, 30));

        jButton8.setText("FR");
        /*jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });*/
        jPanel1.add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 20, -1, -1));
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 150, 210, 20));
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 300, 140, 20));

        jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jList1ValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jList1);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 360, 310, 90));
        jPanel1.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 250, 320, 10));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 861, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 460, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

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

    //********** METHODE CHOISIR IMAGINE **********//
    public void imagemm() {
        jButton4.setEnabled(true);
        jButton5.setEnabled(true);
        jButton6.setEnabled(true);
        jButton7.setEnabled(true);
        //INFORMER LE NOM DE LA FENETRE
        fileChooser.setDialogTitle("Choisir un Image");
        //SEULEMENT LES FICHIER SERONT OUVERTES
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        ExtensionFileFilter filter = new ExtensionFileFilter();
        //CREER FILTRE ET ADICIONER UN EXTENTION DE FICHIER
        filter.addExtension("jpg", true);
        filter.addExtension("gif", true);
        //SANS DESCRIPTION DU FILTRE
        filter.setDescription("");
        //ADICIONER FILTRE
        fileChooser.setFileFilter(filter);
        fileChooser.setAcceptAllFileFilterUsed(false);
        //SANS SELECTION MULTIPLE
        fileChooser.setMultiSelectionEnabled(false);
        Vue vue = null;
        jLabel3.setVisible(true);
        if (fileChooser.showOpenDialog(vue) == JFileChooser.APPROVE_OPTION) {
            modele.arquivo = fileChooser.getSelectedFile();

            jTextField2.setText(modele.arquivo.getAbsolutePath());
            modele.adresse = modele.arquivo.getAbsolutePath();
            BufferedImage bi = null;
            try {
                //POSER L'IMAGE REEL DANS UN BUFFER
                bi = ImageIO.read(modele.arquivo);
            } catch (IOException ex) {
                Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex);
            }
            //MODIFIER TAILLE DE L'IMAGE DANS UNS LABEL
            //CREER BUFFER AUXILIAIRE AVEC UNE TAILLE SOIHAITEE
            BufferedImage aux = new BufferedImage(340, 140, bi.getType());
            //UTILISER CLASSE GRAPHICS POUR FAIRE L'EDITION
            Graphics2D g = aux.createGraphics();
            AffineTransform at = AffineTransform.getScaleInstance((double) 340 / bi.getWidth(), (double) 140 / bi.getHeight());//cria a transformacao  
            g.drawRenderedImage(bi, at);
            //METTRE L'IMAGE DANS LE JLABEL
            jLabel3.setIcon(new ImageIcon(aux));
        }
    }

    public void jButton3ActionPerformed() {                                         
        imagemm();
    }                                        

    //UTILISATION D'UN METHODE DU MODELE
    public void jButton4ActionPerformed() {                                         
        try {
            // to(jTextField3.getText());
            modele.rename(jTextField3.getText());
        } catch (IOException ex) {
            Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex);
        }
        jButton4.setEnabled(false);
    }                                        

    //INTERNATIONALISATION
    public void jButton1ActionPerformed() {                                         

        jLabel1.setText("TRATAR IMAGEM");
        jLabel2.setText("Veja a Imagem:");
        jLabel4.setText("Chave:");
        jButton3.setText("PESQUISAR IMAGEM");
        jButton4.setText("RENOMEAR IMAGEM");
        jButton5.setText("Adicionar");
        jButton6.setText("Modificar");
        jButton7.setText("Pesquisar");

    }                                        

    public void jButton8ActionPerformed() {                                         
        jLabel1.setText("Visionneuse");
        jLabel2.setText("Regarder l'Image:");
        jLabel4.setText("Mots Clés:");
        jButton3.setText("CHOISIR REPERTOIRE D'IMAGE");
        jButton4.setText("MODIFIER LE NOM D'IMAGE");
        jButton5.setText("Adicioner");
        jButton6.setText("Modifier");
        jButton7.setText("Chercher");
    }                                        

    public void jButton2ActionPerformed() {                                         
        jLabel1.setText("&#12471;&#12456; &#12459;&#12458;&#12456;&#12473;");
        jLabel2.setText("&#12452;&#12510;&#12472;&#12455;&#12531;");
        jLabel4.setText("&#12497;&#12521;&#12502;&#12521;");
        jButton3.setText("&#12456;&#12473;&#12467;&#12522;&#12455;&#12523;");
        jButton4.setText("&#12488;&#12521;&#12510;&#12459;&#12458;");
        jButton5.setText("&#12450;&#12482;&#12471;");
        jButton6.setText("&#12514;&#12482;&#12459;");
        jButton7.setText("&#12506;&#12461;&#12469;&#12531;&#12489;");
    }                                        

    //UTILISATION D'UN METHODE DU MODELE
    public void jButton5ActionPerformed() {                                         
        try {
            modele.fichier();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                        

    //UTILISATION D'UN METHODE DU MODELE
    public void jButton7ActionPerformed() {
        try {
            modele.mod2().notify();

        } catch (FileNotFoundException ex) {
            Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Vue.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {                                    
        jList1.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting() && jList1.getSelectedValue() != null) {
                    String path = (jList1.getSelectedValue().toString());
                    //System.out.println("aquiii= " + path);

                    ImageIcon img = new ImageIcon(path);
                    jLabel3.setIcon(img);
                    jLabel3.setVisible(true);
                }
            }
        });
    }                                   

    //********** METHODE PRINCIPAUX - MAIN **********//
    public static void main(String args[]) {
        //CREATION DES OBJETS: VUE, MODELE, CONTROLEUR
        Modele md = new Modele();
        Vue vv = new Vue();
        Controleur cc = new Controleur(md, vv);
        //<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 http://download.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(Vue.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Vue.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Vue.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Vue.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
    }
    public javax.swing.JButton jButton1;
    public javax.swing.JButton jButton2;
    public javax.swing.JButton jButton3;
    public javax.swing.JButton jButton4;
    public javax.swing.JButton jButton5;
    public javax.swing.JButton jButton6;
    public javax.swing.JButton jButton7;
    public javax.swing.JButton jButton8;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabel2;
    public javax.swing.JLabel jLabel3;
    public javax.swing.JLabel jLabel4;
    public javax.swing.JLabel jLabel5;
    public javax.swing.JLabel jLabel6;
    public javax.swing.JList jList1;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JSeparator jSeparator1;
    public javax.swing.JTextField jTextField1;
    public javax.swing.JTextField jTextField2;
    public javax.swing.JTextField jTextField3;

    @Override
    public void update(Observable o, Object arg) {
        throw new UnsupportedOperationException("NON SUPPORTE");
    }
}
MODELO
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;

public class Modele extends Observable {

    public String adresse;
    public File arquivo;
    public FileReader fr;
    public BufferedWriter gravar;
    public BufferedReader br;
    //CREATION DE L'OBJET DU TYPE FENETRE JFileChooser
    JFileChooser fileChooser = new JFileChooser();
    public javax.swing.JButton jButton1;
    public javax.swing.JButton jButton2;
    public javax.swing.JButton jButton3;
    public javax.swing.JButton jButton4;
    public javax.swing.JButton jButton5;
    public javax.swing.JButton jButton6;
    public javax.swing.JButton jButton7;
    public javax.swing.JButton jButton8;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabel2;
    public javax.swing.JLabel jLabel3;
    public javax.swing.JLabel jLabel4;
    public javax.swing.JLabel jLabel5;
    public javax.swing.JLabel jLabel6;
    public javax.swing.JList jList1;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JSeparator jSeparator1;
    public javax.swing.JTextField jTextField1;
    public javax.swing.JTextField jTextField2;
    public javax.swing.JTextField jTextField3;

    //********** METHODES D'ACESS ********// 
    public String getAdresse() {
        return adresse;
    }

    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    public File getArquivo() {
        return arquivo;
    }

    public void setArquivo(File arquivo) {
        this.arquivo = arquivo;
    }

    public FileReader getFileReader() {
        return fr;
    }

    public void setFileReader(FileReader fr) {
        this.fr = fr;
    }

    public BufferedWriter getBufferedWriter() {
        return gravar;
    }

    public void setBufferedWriter(BufferedWriter gravar) {
        this.gravar = gravar;
    }

    public BufferedReader getBufferedReader() {
        return br;
    }

    public void setBufferedReader(BufferedReader br) {
        this.br = br;
    }

    //********** METHODE MODIFIER NOM D'UN FICHIER **********//
    public void rename(String novoNome) throws IOException {
        String temp;
        List<String> lista2 = new ArrayList<String>();
        arquivo = new File(adresse);
        jTextField3.setText(novoNome);

        novoNome = jTextField3.getText().toLowerCase();

        String[] sp = arquivo.getName().split("\\.");
        fr = new FileReader("/Users/Veronica/workspacenetbeans/Visionneuse/mots.txt");
        gravar = new BufferedWriter(new FileWriter("/Users/Veronica/workspacenetbeans/Visionneuse/mots.txt", true));
        br = new BufferedReader(fr);

        while ((temp = br.readLine()) != null) {
            //GENERATION DE LA LISTE (CHAQUE LIGNE DU FICHIER REMPLIRA LA LISTE)     
            if (!temp.contains(jTextField2.getText())) {
                lista2.add(temp);
                System.out.println("NOM N'A PAS ETE ALTERE");
            }
        }
        String qqqq = lista2.toString();
        System.out.println("***LISTA = " + qqqq);

        //REMPLACER LES [, ], ET VIRGULE POUR VIDE, RIEN
        gravar.write(qqqq.replace(",", "\n").replace(" ", "").replace("[", "").replace("]", ""));
        gravar.close();

        if (!jTextField3.getText().isEmpty()) {
            if (arquivo.isFile() == true) {
                arquivo.renameTo(new File(arquivo.getParent() + "\\" + novoNome + "." + sp[1]));
                String nouveau1 = arquivo.getParent() + "\\" + novoNome + "." + sp[1].toString();
                jTextField2.setText(nouveau1);
            } else {
                arquivo.renameTo(new File(arquivo.getParent() + "\\" + novoNome));
            }
        } else {
            jLabel5.setText("INFORMER LE NOUVEAU NOM");
        }
        setChanged();
        notifyObservers();
    }

    //********** METHODE CREER UN FICHIER **********//
    public void fichier() throws FileNotFoundException, IOException {
        arquivo = new File("/Users/Veronica/workspacenetbeans/Visionneuse/mots.txt");

        //SI LE FICHIER N'EXISTE PAS DANS LE REPERTOIRE, IL VA CREER UN NOUVEAU FICHIER   
        if (!arquivo.exists()) {
            try {
                arquivo.createNewFile();
            } catch (IOException e) {
                System.out.println("C'EST PAS POSSIBLE CREER UN FICHIER. A CAUDE DE: " + e.getMessage());
                e.printStackTrace();
            }
        }

        String texto = jTextField1.getText().toUpperCase();
        if (!jTextField1.getText().isEmpty()) {
            try {
                //OBJET QUE VA ECRIRE DANS LE FICHIER TXT    
                gravar = new BufferedWriter(new FileWriter(arquivo, true));

                //IL VA PRENDRE DU SYSTEME LE PARAMETRE DE NOUVELLE LIGNE  
                String quebraDeLinha = System.getProperty("line.separator");

                //ECRITURE NO FICHIER TXT SANS EFFACER LES ANCIENNES REMARQUES  
                gravar.write(jTextField2.getText() + "<>" + texto + "<>" + quebraDeLinha);
                //FERMETURE DU FICHIER
                gravar.close();

            } catch (IOException e) {
                System.out.println("C'EST PAS POSSIBLE CREER UN FICHIER. A CAUDE DE:" + e.getMessage());
                e.printStackTrace();
            }
        } else {
            jLabel6.setText("INFORMER LE MOT CLEF");
        }
    }

    //********** METHODE CHERCHER MOT CLEF **********//
    public String mod2() throws FileNotFoundException, IOException {
        String ende;
        String temp;
        String returnar = null;
        List<String> lista = new ArrayList<String>();

        try {
            //OUVERTURE DU FICHIER     
            fr = new FileReader("/Users/Veronica/workspacenetbeans/Visionneuse/mots.txt");
            gravar = new BufferedWriter(new FileWriter("/Users/Veronica/workspacenetbeans/Visionneuse/mots.txt", true));
            br = new BufferedReader(fr);
            
            //CHAQUE INTERATION EST UNE LIGNE DU FICHIER
            //AFFECTATION A temp
            while ((temp = br.readLine()) != null) {
                //GENERATION DE LA LISTE     
                System.out.println("linhaa TEMP=" + temp);
                String[] a = temp.split("<>");
                for (String each : a) {
                    {
                        //TRANFORMER LES MOTS CLEFS EN MAJUSCULES
                        String editTextUpper = jTextField1.getText().toUpperCase();
                        String eachUpper = each.toUpperCase();
 
                        if (editTextUpper.contains(eachUpper)) {
                            ende = temp;
                            //REMPLACER LES MOTS ENTRE <> POUR VIDE? RIEN
                            ende = ende.replaceAll("\\<>[^)]*\\<>", "");
                            //System.out.println("add imagem="+ende); 
                            lista.add(ende);
                        }
                    }
                    System.out.println("ffff=" + each);
                    returnar = each;
                }
            }
            System.out.println("lista = " + lista);

            DefaultListModel model = new DefaultListModel();
            for (String s : lista) {
                jList1.setModel(model);
                model.addElement(s);
            }
        } catch (FileNotFoundException el) {
            System.out.println("FICHIER N'ETAIT PAS TROUVE");
        } catch (IOException e) {
            e.printStackTrace();
        }
        setChanged();
        notifyObservers();
        return returnar;
    }
}
CONTROLADOR
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Controleur implements ActionListener {

    Modele modele;
    Vue vue;

    Controleur(Modele modele, Vue vue) {
        this.modele = modele;
        this.vue = vue;
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                Controleur.this.vue.addListenersToView(Controleur.this);
            }
        });
        
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
        if (evt.getSource() == vue.jButton1) {
            vue.jButton1ActionPerformed();
            System.out.println("Um");
        }
        
        if (evt.getSource() == vue.jButton2) {
            vue.jButton2ActionPerformed();
            System.out.println("Dois");
        }
        
        if (evt.getSource() == vue.jButton3) {
            vue.jButton3ActionPerformed();
            vue.imagemm();
            System.out.println("3333");
            //Associar fenetre a 
        }
        
        if (evt.getSource() == vue.jButton4) {
            vue.jButton4ActionPerformed();
            System.out.println("444");
        }
        
        if (evt.getSource() == vue.jButton5) {
            vue.jButton5ActionPerformed();
            System.out.println("5555");
        }
        
        if (evt.getSource() == vue.jButton7) {
            vue.jButton7ActionPerformed();
            System.out.println("Sete");
        }
        
        if (evt.getSource() == vue.jButton8) {
            vue.jButton8ActionPerformed();
            System.out.println("8888");
        }
    }
}

O ERRO:
[code]
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Vue.imagemm(Vue.java:216)
at Vue.jButton3ActionPerformed(Vue.java:236)
at Controleur.actionPerformed(Controleur.java:35)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

OBRIGADA DESDE JAH...
VERONICA

2 Respostas

R

Seu código é muito estranho, você misturou no seu model código do swing , além de ser em francês(mas dá pra compreender em partes),mas olha essa parte no seu controller:

if (evt.getSource() == vue.jButton3) {  
            vue.jButton3ActionPerformed();  
            vue.imagemm();  
            System.out.println("3333");  
            //Associar fenetre a   
        }

Se você olhar na sua view você tem esse método:

public void jButton3ActionPerformed() {                                           
        imagemm();  
    }

E no controller no actionPerformed:

if (evt.getSource() == vue.jButton3) {  
            vue.jButton3ActionPerformed();  
            vue.imagemm();  
            System.out.println("3333");  
            //Associar fenetre a   
        }

Você está chamando esse método imagemm();
2 vezes,uma internamente na view e outra no controller,talvez seja isso o seu problema. Debuga esse código,prq pra mim ele tá meio bizarro,e também é melhor você rever os seus conceitos de mvc.

V

Obrigada, nao tinha me atendado para as duas chamadas de método.
Os comentarios realmente estao em francês, estudo aqui numa faculdade francesa e é obrigatorio! =s

Tem como me dar umas dicas de como melhorar meu codigo, o Controlador chama os metodos da Visao; a Visao usa os metodos do Modelo e seus atributos, o COntrolador usa Listeners e Actions, como e porque?

Obrigada,

Criado 16 de fevereiro de 2013
Ultima resposta 17 de fev. de 2013
Respostas 2
Participantes 2