Amigos,
Estou com um controle de viagens e se eu compilar no NetBeans ele funciona TUDO, mas se eu criar o arquivo JAR ele nao abre o relatorio solicitado. Abaixo vou descrever o q eu fiz:
//Este formulário verifica uma variavel publica, se ela tem o valor “frmPrincipal” ele chama o relatório, se o valor for “Movimentos” ele chama o formulário de movimentos.
Acontece que se eu for pelo arquivo JAR ele nao chama o relatório. No final colocarei o codigo para o relatório.
[code]/*
- FiltroMovimento.java
- Created on 28 de Fevereiro de 2008, 20:45
*/
package Cadastros;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;
import Cadastros.*;
import java.sql.SQLException;
import utilitarios.conexao;
/**
*
-
@author Administrador
*/
public class FiltroMovimento extends javax.swing.JFrame {
conexao TabelaAnalistas;public static javax.swing.JButton getBtFiltrar() {
return btFiltrar;
}public static javax.swing.JFormattedTextField getDtFim() {
return dtFim;
}public static javax.swing.JFormattedTextField getDtInicio() {
return dtInicio;
}public static javax.swing.JTextField getTxtCodigo() {
return txtCodigo;
}public static javax.swing.JTextField getTxtNome() {
return txtNome;
}
private MaskFormatter FormatoData;/** Creates new form FiltroMovimento */
public FiltroMovimento() {
initComponents();
//frmPrincipal.FormAberto = “FiltroMovimento”;TabelaAnalistas = new conexao(); TabelaAnalistas.conecta(); TabelaAnalistas.executeSQL("SELECT * FROM ANALISTAS"); dtFim.setEnabled(false); dtInicio.setEnabled(false); btFiltrar.setEnabled(false);}
/** 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.
*/
//
private void initComponents() {jLabel1 = new javax.swing.JLabel();
try
{
FormatoData = new MaskFormatter("##/##/####");
}
catch(Exception erro)
{
JOptionPane.showMessageDialog(null, “N�o foi poss�vel setar a data!” + erro);
}
dtInicio = new JFormattedTextField(FormatoData);
jLabel2 = new javax.swing.JLabel();
try
{
FormatoData = new MaskFormatter("##/##/####");
}
catch(Exception erro)
{
JOptionPane.showMessageDialog(null, “N�o foi poss�vel setar a data!” + erro);
}
dtFim = new JFormattedTextField(FormatoData);
btFiltrar = new javax.swing.JButton();
txtCodigo = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
txtNome = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(“Insira o Filtro.”);
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));jLabel1.setText(“Dt. Inicio”);
jLabel2.setText(“Dt. Final”);
btFiltrar.setText(“Filtrar”);
btFiltrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btFiltrarActionPerformed(evt);
}
});txtCodigo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtCodigoActionPerformed(evt);
}
});jLabel3.setText(“C�digo Analista”);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});jPanel1.setBackground(new java.awt.Color(0, 0, 255));
jPanel1.setForeground(new java.awt.Color(0, 0, 255));jLabel4.setFont(new java.awt.Font(“Tahoma”, 1, 14));
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText(“Insira o Filtro abaixo:”);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()
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
);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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3)
.addGroup(layout.createSequentialGroup()
.addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(dtInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(dtFim, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btFiltrar))
.addComponent(jLabel2))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btFiltrar)
.addComponent(dtFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(dtInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(44, Short.MAX_VALUE))
);java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-469)/2, (screenSize.height-204)/2, 469, 204);
}//
private void btFiltrarActionPerformed(java.awt.event.ActionEvent evt) {
String Ini = getDtInicio().getText().substring(3, 5) + “/” + getDtInicio().getText().substring(0, 2) + “/” + getDtInicio().getText().substring(6, 10);
String Fim = getDtFim().getText().substring(3, 5) + “/” + getDtFim().getText().substring(0, 2) + “/” + getDtFim().getText().substring(6, 10);Movimentos.strSQL = “SELECT * FROM DESPESAVIAGEM WHERE DATAMOV BETWEEN #” + Ini + “# AND #” + Fim + “# AND USUARIO=’” + Movimentos.Usuario + “’ ORDER BY DATAMOV ASC”;
//System.out.println(Movimentos.strSQL);
if (frmPrincipal.FormAberto.equalsIgnoreCase(“frmPrincipal”)) {
new relatorios.RelMovimentos();
//dispose();
}
else if (frmPrincipal.FormAberto.equalsIgnoreCase(“Movimentos”)){
new Movimentos().show();
dispose();
} -
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
new PesquisarAnalista().show();
dispose();
}
private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {
String aux = txtCodigo.getText();
aux = "000000" + aux;
aux = aux.substring(aux.length() - 6);
txtCodigo.setText(aux);
txtCodigo.setBackground(new java.awt.Color(235, 233, 237));
try {
String sql = "SELECT * FROM ANALISTAS WHERE CODIGO ='"+ txtCodigo.getText() + "'";
TabelaAnalistas.executeSQL(sql);
TabelaAnalistas.resultset.first();
txtNome.setText(TabelaAnalistas.resultset.getString("NmAnalista"));
Movimentos.Usuario = TabelaAnalistas.resultset.getString("Login");
sql = "SELECT * FROM ANALISTAS";
TabelaAnalistas.executeSQL(sql);
TabelaAnalistas.resultset.first();
FiltroMovimento.getDtFim().setEnabled(true);
FiltroMovimento.getDtInicio().setEnabled(true);
FiltroMovimento.getBtFiltrar().setEnabled(true);
FiltroMovimento.getDtInicio().requestFocus();
} catch (SQLException erro) {
JOptionPane.showMessageDialog(null, "Nao foi possivel localizar o Cliente" + txtCodigo.getText());
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FiltroMovimento().setVisible(true);
}
});
}
// Variables declaration - do not modify
public static javax.swing.JButton btFiltrar;
public static javax.swing.JFormattedTextField dtFim;
public static javax.swing.JFormattedTextField dtInicio;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
public static javax.swing.JTextField txtCodigo;
public static javax.swing.JTextField txtNome;
// End of variables declaration
//private static javax.swing.JTextField txtNome;
}[/code]
//este é o do relatorio em si.
[code]package relatorios;
import java.util.HashMap;
import javax.swing.JOptionPane;
import Cadastros.*;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import utilitarios.conexao;
public class RelMovimentos {
conexao con = new conexao();
public RelMovimentos() {
try {
con.conecta();
con.executeSQL(Movimentos.strSQL);
JRResultSetDataSource jrRS = new JRResultSetDataSource(con.resultset);
JasperPrint jasperPrint = JasperFillManager.fillReport(
"relatorios/RelMovimentos.jasper", new HashMap(), jrRS);
JasperViewer.viewReport(jasperPrint);
} catch (Exception erro) {
JOptionPane.showMessageDialog(null, "deu erro =" + erro);
}
}
public static void main(String args[]) {
new RelMovimentos();
}
}[/code]
Como sair desta?

