ERRO Bizarro no JDesktop Pane

8 respostas
P

problemas no jdesktoppane eu mando fechar um jinternal frame e ele fecha na hora que mando abrir de novo ele da um erro bizarro

xception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1  
    at java.util.Vector.elementData(Vector.java:730)  
    at java.util.Vector.elementAt(Vector.java:473)  
    at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:665)  
    at automaticnewsletter.interfacing.DB.consultadb(DB.java:42)  
    at automaticnewsletter.interfacing.Desk.abreRemessa(Desk.java:201)  
    at automaticnewsletter.interfacing.Desk.jMenuItem4ActionPerformed(Desk.java:157)  
    at automaticnewsletter.interfacing.Desk.access$000(Desk.java:23)  
    at automaticnewsletter.interfacing.Desk$1.actionPerformed(Desk.java:101)  
    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.AbstractButton.doClick(AbstractButton.java:376)  
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)  
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)  
    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:703)  
    at java.awt.EventQueue.access$000(EventQueue.java:102)  
    at java.awt.EventQueue$3.run(EventQueue.java:662)  
    at java.awt.EventQueue$3.run(EventQueue.java:660)  
    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:676)  
    at java.awt.EventQueue$4.run(EventQueue.java:674)  
    at java.security.AccessController.doPrivileged(Native Method)  
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)  
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)  
    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)  
CONSTRUÍDO COM SUCESSO (tempo total: 14 segundos)

segue a classe

package automaticnewsletter.interfacing;  
  
  
import automaticnewsletter.createNews.News;  
import automaticnewsletter.createNews.Newsletter_interface;  
import automaticnewsletter.createNews.newsletter;  
import java.awt.Container;  
import java.awt.Dimension;  
import java.awt.Toolkit;  
import java.net.URL;  
import javax.swing.JOptionPane;  
import javax.swing.table.DefaultTableModel;  
  
  
/** 
* 
* @author pedro 
*/  
public class Desk extends javax.swing.JFrame implements Newsletter_interface // , SmbInterface  
{  
  
    /** 
     * Creates new form Desk 
     */  
    public Desk()   //construtor  
    {  
        this.setTitle("Newsletter");  
        init();  
    }  
        
    private void init() // inicia os componentes da classe  
    {          
        initComponents();  
        getDesktopSize();  
        this.setVisible(true);       
    }            
      
    private void getDesktopSize() //auto-redimensionamento  
    {  
        _c= getContentPane();    
        tela = Toolkit.getDefaultToolkit().getScreenSize();    
        this.setSize(tela.width-50, tela.height-100);     
        //dc.gc.setTime(dc.d);  // 0=janeiro 6= julho   
     }  
     
        
    /** 
     * 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() {  
  
        jPanel1 = new javax.swing.JPanel();  
        jDesktopPane1 = new javax.swing.JDesktopPane();  
        jMenuBar1 = new javax.swing.JMenuBar();  
        jMenu1 = new javax.swing.JMenu();  
        jMenuItem1 = new javax.swing.JMenuItem();  
        jMenuItem2 = new javax.swing.JMenuItem();  
        jMenu3 = new javax.swing.JMenu();  
        jMenuItem4 = new javax.swing.JMenuItem();  
        jMenuItem5 = new javax.swing.JMenuItem();  
        jMenu2 = new javax.swing.JMenu();  
        jMenuItem3 = new javax.swing.JMenuItem();  
  
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);  
  
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);  
        jPanel1.setLayout(jPanel1Layout);  
        jPanel1Layout.setHorizontalGroup(  
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)  
        );  
        jPanel1Layout.setVerticalGroup(  
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)  
        );  
  
        jMenu1.setText("Arquivo");  
  
        jMenuItem1.setText("Configurações");  
        jMenu1.add(jMenuItem1);  
  
        jMenuItem2.setText("Sair");  
        jMenu1.add(jMenuItem2);  
  
        jMenuBar1.add(jMenu1);  
  
        jMenu3.setText("Remessa");  
  
        jMenuItem4.setText("Gerar");  
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {  
            public void actionPerformed(java.awt.event.ActionEvent evt) {  
                jMenuItem4ActionPerformed(evt);  
            }  
        });  
        jMenu3.add(jMenuItem4);  
  
        jMenuItem5.setText("Enviar");  
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {  
            public void actionPerformed(java.awt.event.ActionEvent evt) {  
                jMenuItem5ActionPerformed(evt);  
            }  
        });  
        jMenu3.add(jMenuItem5);  
  
        jMenuBar1.add(jMenu3);  
  
        jMenu2.setText("Sobre");  
  
        jMenuItem3.setText("Sobre");  
        jMenu2.add(jMenuItem3);  
  
        jMenuBar1.add(jMenu2);  
  
        setJMenuBar(jMenuBar1);  
  
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
        getContentPane().setLayout(layout);  
        layout.setHorizontalGroup(  
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)  
        );  
        layout.setVerticalGroup(  
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)  
        );  
  
        pack();  
    }// </editor-fold>                          
  
    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:  
         if(evt.getSource()==jMenuItem4)  
         {  
              
             if(jDesktopPane1.getComponentCount()>0)  
             {  
                jDesktopPane1.removeAll();    
                   
             }  
             else  
             {      
                   
                 abreRemessa();  
             }  
         }  
           
         /* 
          *  
          */  
    }                                            
  
    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:  
        if(evt.getSource()==jMenuItem5)  
        {     
            /* 
            String novo= dc.getNextNews("15","segunda"); 
            int _dia, mes; //2012-07-12            
            mes = Integer.parseInt(novo.substring(6,7)); 
            _dia=Integer.parseInt(novo.substring(9,10));   
            dc.getFeriado(mes, _dia);*/  
            if(jDesktopPane1.getComponentCount()>0)  
            {  
                    rm.getFiles();  
                    boolean flag=false;  
                    if(flag==true)  
                    {                         
                        JOptionPane.showMessageDialog(null, "E-mails enviados con sucesso!!!","Info",JOptionPane.INFORMATION_MESSAGE);                          
                    }  
                    else  
                    {  
                        JOptionPane.showMessageDialog(null, "Não foi possivel enviar o email","Erro 04",JOptionPane.INFORMATION_MESSAGE);  
                    }  
            }  
            else  
            {  
                    System.out.println("null");  
                    JOptionPane.showMessageDialog(null, "Por favor vá em no menu 'Remessa'\ne clique na opção 'Gerar' \n e depois clique em 'Enviar'", "Erro 02", WIDTH);  
            }  
        }          
    }                                            
  
      
    private void abreRemessa()  
    {  
        rm = new Remessa();  
        con.consultadb("Select * from tb_canal_hotsite order by nome_canal");                    
        rm.jButton2.setSize(jDesktopPane1.getWidth()-150, 25);  
        rm.setSize(jDesktopPane1.getWidth()-110, jDesktopPane1.getHeight()-110);  
        rm.jTable1.setModel(new DefaultTableModel());      
        rm.jTable1.setModel(con.modelo);  
        rm.setVisible(true);                    
        jDesktopPane1.add(rm);   
         
    }

Eu abro o Jinternal frame remessa pela primeira vez e funciona eu cliclo no botão fechar ele fecha ai quando eu clico no jmeuBar para reabrir este mesmo Jinternalframe da esse erro

Alguém sabe como posso corrigir este erro

8 Respostas

P

up

rsantik

Será que quando você fecha está deletando o objeto. E quando você vai abrir não consegue mais achar o objeto deletado? Quando o menu é carregado, você cria o objeto, quando fecha, o deleta, e quando vai abrir novamente dá erro porque não achou o objeto.

P

Vou te enviar o form da classe remessa, mas acho que não mando deletar uso o this.dispose();

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package automaticnewsletter.interfacing;

import automaticnewsletter.IO.IO;
import automaticnewsletter.IO.SmbIO;
import automaticnewsletter.IO.SmbInterface;
import automaticnewsletter.emailserver.SendMail;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author pedro
 */
public class Remessa extends javax.swing.JInternalFrame implements SmbInterface
{

    /**
     * Creates new form Remessa
     */
    public Remessa() 
    {
        super("Lista de Newsletter",true);
        initComponents();       
        this.setResizable(false);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.pack();
    }

    /**
     * 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() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable() {public boolean isCellEditable(int rowIndex, int colIndex)
            {        //Se a coluna for diferente de 3 ele deixa editar.
                return false;
            }
        };
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable1);

        getContentPane().add(jScrollPane2, java.awt.BorderLayout.PAGE_START);

        jButton1.setIcon(new javax.swing.ImageIcon("/home/pedro/NetBeansProjects/AutomaticNewsletter/package/1342463759_cancel.png")); // NOI18N
        jButton1.setText("Fechar");
        jButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, java.awt.BorderLayout.CENTER);

        jButton2.setIcon(new javax.swing.ImageIcon("/home/pedro/NetBeansProjects/AutomaticNewsletter/package/1342466818_Preview01.png")); // NOI18N
        jButton2.setText("Visualizar");
        jButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, java.awt.BorderLayout.PAGE_END);

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

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        if(evt.getSource()==jButton2)
        {
           boolean _ok= getFiles();
           if(_ok==true)
           {
               doPreview(); 
           }
           else 
           {
               JOptionPane.showMessageDialog(null, "Não foi possível localizar\nos arquivos para o preview! ","Erro 03",JOptionPane.INFORMATION_MESSAGE);
           }
        }
    }                                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:         
       this.dispose();
       this.setVisible(false);
    }

    protected boolean getFiles()
    {
         if(jTable1.getSelectedRow()!=-1 && jTable1.getSelectedColumn()<9)
         { 
                 local= io.getSystempath();
                 id =jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString();
                 local=local.concat("/ASP/");
                 local=local.concat(id+"/");
                 file = jTable1.getValueAt(jTable1.getSelectedRow(), 7).toString();
                 System.out.println(local+file);
                 url=jTable1.getValueAt(jTable1.getSelectedRow(), 6).toString();
                 System.out.println(url);                 
                 try 
                 {
                     isCopy =copia(url, "//UNIX/"+id+"/"+file);
                     System.out.println(isCopy);
                 } 
                 catch (ClassNotFoundException | IOException ex) 
                 {
                    Logger.getLogger(Remessa.class.getName()).log(Level.SEVERE, null, ex);
                 }
            }
            else{}
         return  isCopy;
    }
    
    private void doPreview()
    {  
                 if(isCopy==true)
                 {
                      view = new preview();
                      view.setVisible(true);
                      if(file.contains("html"))
                      {
                          view.exibeHTML(local+file);
                      }
                      else if(file.contains("pdf"))
                      {
                          view.exibePDF(local+file);
                      }
                      else if(file.contains("jpg") || file.contains("Jpeg"))
                      {
                          view.exibeJPEG(local+file);
                      }
                      else
                      {
                          
                      }
                 }
                 else
                 {}
    }
    
    @Override
    //copia("//192.168.50.4/ABEQ/index.html","//unix/ASP/index2.html"); 
    public boolean copia(String diretorio, String destino) throws ClassNotFoundException, IOException 
    {
        isCopy=false;
        smbIO=new SmbIO();
        isCopy=smbIO.copia(diretorio,destino);
        return isCopy;
    }
    
    protected boolean  envia(String destinatário, String message)
    {
        try 
        {
           isOK=false;
           String path = " ";
           path = path.concat(local+file).trim();
           System.out.println("path "+path);
           int i = jTable1.getSelectedRow();
           if(!path.trim().equalsIgnoreCase("") || !path.equalsIgnoreCase(null))
           {
                sm= new SendMail();               
                // if 1 email com anexo
                if(jTable1.getValueAt(i, 8).toString().equalsIgnoreCase("1") || file.contains("pdf"))
                {
                     sm.setSendMail("smtp.bilheteria.com", "25");         
                     sm.sendMail("[email removido]");
                     sm.setUser("[email removido]", "teatro");
                     sm.Authentication();            
                     sm.setMessage("[email removido]", "[email removido]", "Hello World");
                     sm.setAttachment(path,"Newsletter");
                     sm.Envia();
                     isOK=true;
                }
                // if 2 email com anexo no corpo
                else if(jTable1.getValueAt(i, 8).toString().equalsIgnoreCase("2") || !file.contains("pdf"))
                {
                    sm._htmlMail(path,"[email removido]","Pedro","Newsletter");
                    isOK=true;
                }
           }
           else
           {
               isOK=false;
           }
        } 
        catch (Exception ex)
        {
            isOK=false;
            System.err.println(ex);
        }
        return isOK;
    }
    
    protected  boolean Remessa()
    {
        remessa = new String[jTable1.getRowCount()][jTable1.getColumnCount()];
        return ok;
    }
 
    // Variables declaration - do not modify
    public transient javax.swing.JButton jButton1;
    public javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane2;
    public javax.swing.JTable jTable1;
    // End of variables declaration
    private boolean isCopy=false , ok=false;
    private transient SmbIO smbIO;
    private preview view;
    private String  id, file, url, local;
    private IO io = new IO();
    protected  transient SendMail sm;
    public transient boolean  isOK=false;   
    protected String remessa [][];
    

  
}
ViniGodoy

Por favor não “upe” tópicos. Pelo menos, não sem complementa-lo com mais informações.

Por exemplo, seu erro indica que o problema ocorreu em na classe DB.java, na linha 42:

E, no entando, você não postou o que existe nessa classe. Esse é um bom lugar para você colocar um breakpoint também.

Para evitar vários e vários e vários problemas com o JTable, você deveria aprender a fazer seu próprio TableModel. Não usar o Default.
Dê uma olhada no link da minha assinatura e aprenda como.

Finalmente, movi seu tópico para o fórum de interface gráfica.

rsantik

então, mas se vc dá um Dispose no objeto quando fecha a internalFrame, você tem que instancia-lo novamente quando o usuário clica no Menu para abrir a InternalFramew novamente.

P

então mas eu deixo do seguinte jeiro

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
         if(evt.getSource()==jMenuItem4)
         {     
                 rm = new Remessa();                  
                 con.consultadb("Select * from tb_canal_hotsite order by nome_canal");                  
                 rm.jButton2.setSize(jDesktopPane1.getWidth()-150, 25);
                 rm.jButton1.setSize(jDesktopPane1.getWidth()-150, 25);
                 rm.setSize(jDesktopPane1.getWidth()-110, jDesktopPane1.getHeight()-110);                 
                 rm.jTable1.setModel(con.modelo);
                 jDesktopPane1.add(rm,1);  
                 rm.setVisible(true);
                 if(rm.isVisible()==true)
                 {         
                     System.out.println(" é visivel");
                 }
                 else if(rm.isVisible()==false)
                 {
                     System.out.println("não é visivel");
                     
                     jDesktopPane1.remove(rm);
                 }
              
         }
ViniGodoy

Pode postar a classe e a linha informada no erro que eu coloquei ali em cima?
O que tem na DB.java, linha 42? Posta todo o método consultaDb

P

Corrigido fiz a seguinte coisa:

import automaticnewsletter.IO.IO;
import automaticnewsletter.IO.SmbIO;
import automaticnewsletter.IO.SmbInterface;
import automaticnewsletter.emailserver.SendMail;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author pedro
 */
public class Remessa extends javax.swing.JInternalFrame implements SmbInterface
{

    /**
     * Creates new form Remessa
     */
    public Remessa() 
    {
        super("Lista de Newsletter",true);        
        initComponents(); 
        init();
        this.setResizable(false);
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);
        this.pack();
    }
  
    public void getDesktopSize(int widht, int height) //auto-redimensionamento
    {
        jButton2.setSize(widht-150, 25);
        jButton1.setSize(widht-150, 25);
        this.setSize(widht-110, height-110); 
     }
    
    private  void init()
    {
        db = new DB();
        db.consultadb("Select * from tb_canal_hotsite order by nome_canal");         
        jTable1.setModel(db.modelo);
    }
    
    /**
     * 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() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable() {public boolean isCellEditable(int rowIndex, int colIndex)
            {        //Se a coluna for diferente de 3 ele deixa editar.
                return false;
            }
        };
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable1);

        getContentPane().add(jScrollPane2, java.awt.BorderLayout.PAGE_START);

        jButton1.setIcon(new javax.swing.ImageIcon("/home/pedro/NetBeansProjects/AutomaticNewsletter/package/1342463759_cancel.png")); // NOI18N
        jButton1.setText("Fechar");
        jButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, java.awt.BorderLayout.CENTER);

        jButton2.setIcon(new javax.swing.ImageIcon("/home/pedro/NetBeansProjects/AutomaticNewsletter/package/1342466818_Preview01.png")); // NOI18N
        jButton2.setText("Visualizar");
        jButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, java.awt.BorderLayout.PAGE_END);

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

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        if(evt.getSource()==jButton2)
        {
           boolean _ok= getFiles();
           if(_ok==true)
           {
               doPreview(); 
           }
           else 
           {
               JOptionPane.showMessageDialog(null, "Não foi possível localizar\nos arquivos para o preview! ","Erro 03",JOptionPane.INFORMATION_MESSAGE);
           }
        }
    }                                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:         
       //this.dispose();
       db=null;
       this.doDefaultCloseAction();
       this.setVisible(false);
    }                                        

    protected boolean getFiles()
    {
         if(jTable1.getSelectedRow()!=-1 && jTable1.getSelectedColumn()<9)
         { 
                 local= io.getSystempath();
                 id =jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString();
                 local=local.concat("/ASP/");
                 local=local.concat(id+"/");
                 file = jTable1.getValueAt(jTable1.getSelectedRow(), 7).toString();
                 System.out.println(local+file);
                 url=jTable1.getValueAt(jTable1.getSelectedRow(), 6).toString();
                 System.out.println(url);                 
                 try 
                 {
                     isCopy =copia(url, "//UNIX/"+id+"/"+file);
                     System.out.println(isCopy);
                 } 
                 catch (ClassNotFoundException | IOException ex) 
                 {
                    Logger.getLogger(Remessa.class.getName()).log(Level.SEVERE, null, ex);
                 }
            }
            else{}
         return  isCopy;
    }
    
    private void doPreview()
    {  
                 if(isCopy==true)
                 {
                      view = new preview();
                      view.setVisible(true);
                      if(file.contains("html"))
                      {
                          view.exibeHTML(local+file);
                      }
                      else if(file.contains("pdf"))
                      {
                          view.exibePDF(local+file);
                      }
                      else if(file.contains("jpg") || file.contains("Jpeg"))
                      {
                          view.exibeJPEG(local+file);
                      }
                      else
                      {
                          
                      }
                 }
                 else
                 {}
    }
    
    @Override
    //copia("//192.168.50.4/ABEQ/index.html","//unix/ASP/index2.html"); 
    public boolean copia(String diretorio, String destino) throws ClassNotFoundException, IOException 
    {
        isCopy=false;
        smbIO=new SmbIO();
        isCopy=smbIO.copia(diretorio,destino);
        return isCopy;
    }
    
    protected boolean  envia(String destinatário, String message)
    {
        try 
        {
           isOK=false;
           String path = " ";
           path = path.concat(local+file).trim();
           System.out.println("path "+path);
           int i = jTable1.getSelectedRow();
           if(!path.trim().equalsIgnoreCase("") || !path.equalsIgnoreCase(null))
           {
                sm= new SendMail();               
                // if 1 email com anexo
                if(jTable1.getValueAt(i, 8).toString().equalsIgnoreCase("1") || file.contains("pdf"))
                {
                     sm.setSendMail("smtp.bilheteria.com", "25");         
                     sm.sendMail("[email removido]");
                     sm.setUser("[email removido]", "teatro");
                     sm.Authentication();            
                     sm.setMessage("[email removido]", "[email removido]", "Hello World");
                     sm.setAttachment(path,"Newsletter");
                     sm.Envia();
                     isOK=true;
                }
                // if 2 email com anexo no corpo
                else if(jTable1.getValueAt(i, 8).toString().equalsIgnoreCase("2") || !file.contains("pdf"))
                {
                    sm._htmlMail(path,"[email removido]","Pedro","Newsletter");
                    isOK=true;
                }
           }
           else
           {
               isOK=false;
           }
        } 
        catch (Exception ex)
        {
            isOK=false;
            System.err.println(ex);
        }
        return isOK;
    }
    
    protected  boolean Remessa()
    {
        remessa = new String[jTable1.getRowCount()][jTable1.getColumnCount()];
        return ok;
    }
 
    // Variables declaration - do not modify                     
    public transient javax.swing.JButton jButton1;
    public javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane2;
    public javax.swing.JTable jTable1;
    // End of variables declaration                   
    private boolean isCopy=false , ok=false;
    private transient SmbIO smbIO;
    private preview view;
    private String  id, file, url, local;
    private IO io = new IO();
    protected  transient SendMail sm;
    public transient boolean  isOK=false;   
    protected String remessa [][];
    private DB db;
Criado 18 de julho de 2012
Ultima resposta 18 de jul. de 2012
Respostas 8
Participantes 3