<package telas;
import DAO.BuscaCodigoDAO;
import DAO.DAOException;
import java.io.File;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import model.ModelReport;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JasperViewer;
public class telaImpressãoEtiquetas extends javax.swing.JInternalFrame {
public telaImpressãoEtiquetas() {
initComponents();
Campo2.setEditable(false);
Campo3.setEditable(false);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
Campo1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
Campo2 = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
Campo3 = new javax.swing.JTextField();
imprime1Btn = new javax.swing.JButton();
imprime2Btn = new javax.swing.JButton();
setClosable(true);
setTitle("Impressão de Etiquetas");
jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
jLabel1.setText("Código Atual:");
jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
jLabel2.setText("Imprimir apenas uma etiqueta");
jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
jLabel3.setText("Imprimir etiquetas em sequência");
jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
jLabel4.setText("Código de:");
jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
jLabel5.setText("à");
imprime1Btn.setText("Imprimir");
imprime1Btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
imprime1BtnActionPerformed(evt);
}
});
imprime2Btn.setText("Imprimir");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Campo1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(imprime1Btn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Campo2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Campo3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(imprime2Btn)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(Campo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(imprime1Btn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(Campo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(Campo3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(imprime2Btn))
.addContainerGap(23, Short.MAX_VALUE))
);
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 imprime1BtnActionPerformed(java.awt.event.ActionEvent evt) {
File arquivo = new File("etiqueta.jasper");
String caminho = arquivo.getAbsolutePath();
try {
BuscaCodigoDAO lista = new BuscaCodigoDAO();
List<ModelReport> list;
list = lista.busca(Integer.parseInt(Campo1.getText()));
JasperReport relatorio;
relatorio = JasperCompileManager.compileReport(caminho);
JRBeanCollectionDataSource dados = new JRBeanCollectionDataSource(list,true);
JasperPrint print = JasperFillManager.fillReport(relatorio, null, dados);
JasperViewer view = new JasperViewer(print, false);
view.setVisible(true);
view.toFront();
JOptionPane.showMessageDialog(null,"Impressão concluída!");
} catch (JRException ex) {
java.util.logging.Logger.getLogger(telaImpressãoEtiquetas.class.getName()).log(Level.SEVERE, null, ex);
} catch (DAOException ex) {
java.util.logging.Logger.getLogger(telaImpressãoEtiquetas.class.getName()).log(Level.SEVERE, null, ex);
}
}
// Variables declaration - do not modify
private javax.swing.JTextField Campo1;
private javax.swing.JTextField Campo2;
private javax.swing.JTextField Campo3;
private javax.swing.JButton imprime1Btn;
private javax.swing.JButton imprime2Btn;
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.JPanel jPanel1;
// End of variables declaration
}