sexta-feira, 18 de dezembro de 2009

Re: [java-br] classe jrabstractscriplet

·

 


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import net.sf.jasperreports.engine.JRAbstractScriptlet;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JRScriptletException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.fill.JRFillField;
import net.sf.jasperreports.view.JasperViewer;

public class Chamada_Relatorio extends JRAbstractScriptlet implements ActionListener {

private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel1 = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JButton jButton3 = null;
private JFrame frame = null ;

public Chamada_Relatorio() {
super();
initialize();
}

private void initialize() {
frame = new JFrame();
frame.setSize(300, 300);
frame.setLocation(10, 10);
frame.setContentPane(getJContentPane());
frame.setTitle("Chamada Relatório");
frame.setLayout(null);
frame.setResizable(false);
frame.setVisible(true);
}

private JPanel getJContentPane() {
if (jContentPane == null) {

jContentPane = new JPanel();
jContentPane.setVisible(true);
jContentPane.setLayout(null);

jLabel1 = new JLabel("Chamada de relatorios .jasper");
jLabel1.setVisible(true);
jLabel1.setBounds(10, 10, 200, 25);

jContentPane.add(jLabel1, null);
jContentPane.add(getJButton1(), null);
jContentPane.add(getJButton2(), null);
jContentPane.add(getJButton3(), null);
}
return jContentPane;
}

private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton("zonas relatorio");
jButton1.setBounds(10, 40, 200, 25);
jButton1.setVisible(true);
jButton1.addActionListener(this);
}
return jButton1;
}

private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton("modelo relatorio SQL");
jButton2.setBounds(10, 70, 200, 25);
jButton2.setVisible(true);
jButton2.addActionListener(this);
}
return jButton2;
}

private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton("metodos relatorio");
jButton3.setBounds(10, 100, 200, 25);
jButton3.setVisible(true);
jButton3.addActionListener(this);
}
return jButton3;
}

public void actionPerformed(ActionEvent ee) {

if (ee.getSource() == jButton3) {

try {
//beforeReportInit() ;
afterColumnInit();
} catch (JRScriptletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Connection con123 = Conexao.obterConexao();
ResultSet rst123 = Conexao.execSQL( " select nome from fofun ; " ) ;
JRResultSetDataSource jrRS123 = new JRResultSetDataSource(rst123);
HashMap parametros123 = new HashMap();

JasperPrint jasperPrint123 = null;
try {
jasperPrint123 = JasperFillManager.fillReport( "C:/eclipse/workspace/teste/src/report/teste1.jasper" , parametros123, jrRS123);
} catch (JRException e1) {
JOptionPane.showMessageDialog(null, "Erro 1 ! \n" + e1.getMessage(), "Operador", JOptionPane.ERROR_MESSAGE);
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "Erro 2 ! \n" + e2.getMessage(), "Operador", JOptionPane.ERROR_MESSAGE);
}

JasperViewer jrviewer123 = new JasperViewer(jasperPrint123, false);
jrviewer123.setVisible(true);

}

if (ee.getSource() == jButton2) {

JasperPrint relat = null;
JRResultSetDataSource jrRS = null;
HashMap map = new HashMap();

Connection con1 = null;
Statement stm1 = null;
ResultSet rst1 = null;

try {
Class.forName("org.postgresql.Driver");
con1 = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ambientelivre3","ambientelivre3", "jmibct123");
stm1 = con1.createStatement();
rst1 = stm1.executeQuery(" select estabelecimento, fone, fax, cep, estado, cidade, endereco, bairro from escola70 ; ");
jrRS = new JRResultSetDataSource(rst1);
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null,"Barra_Ferramenta - Erro 1 ! \n" + e1.getMessage(),"Operador", JOptionPane.ERROR_MESSAGE);
} catch (ClassNotFoundException e2) {
JOptionPane.showMessageDialog(null,"Barra_Ferramenta - Erro 2 ! \n" + e2.getMessage(),"Operador", JOptionPane.ERROR_MESSAGE);
} catch (Exception e3) {
JOptionPane.showMessageDialog(null,"Barra_Ferramenta - Erro 3 ! \n" + e3.getMessage(),"Operador", JOptionPane.ERROR_MESSAGE);
}

try {
relat = JasperFillManager.fillReport("C:/eclipse/workspace/teste/src/report/modelo_relatorio.jasper",map, jrRS);
} catch (JRException e1) {
JOptionPane.showMessageDialog(null,"Erro 1 ao chamar relatório !\n" + e1.getMessage(),"Operador", JOptionPane.ERROR_MESSAGE);
} catch (Exception e2) {
JOptionPane.showMessageDialog(null,"Erro 2 ao chamar relatório !\n" + e2.getMessage(),"Operador", JOptionPane.ERROR_MESSAGE);
}

if (!(relat == null))
JasperViewer.viewReport(relat, false);
else
JOptionPane.showMessageDialog(null, "Erro ", "Operador", JOptionPane.ERROR_MESSAGE);

}

if (ee.getSource() == jButton1) {
JasperPrint relat = null;
JRResultSetDataSource jrRS = null;
HashMap map = null;

try {
relat = JasperFillManager.fillReport( "C:/eclipse/workspace/teste/src/report/Zonas.jasper", map, jrRS);
} catch (JRException e1) {
JOptionPane.showMessageDialog(null, "Erro 1 ao chamar relatório !\n" + e1.getMessage(), "Operador", JOptionPane.ERROR_MESSAGE);
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "Erro 2 ao chamar relatório !\n" + e2.getMessage(), "Operador", JOptionPane.ERROR_MESSAGE);
}

if (!(relat == null))
JasperViewer.viewReport(relat, false);
else
JOptionPane.showMessageDialog(null, "Erro ", "Operador", JOptionPane.ERROR_MESSAGE);

}

}

public void afterColumnInit() throws JRScriptletException {
System.out.println("apos iniciar coluna");

String contador = "" ;
contador = (String) ((JRFillField)this.fieldsMap.get("PAGE_COUNT")).getValue() ;
System.out.println( contador ) ;

}

public void afterDetailEval() throws JRScriptletException {
System.out.println("apos feito a banda detail") ;
}

public void afterGroupInit(String arg0) throws JRScriptletException {
System.out.println("apos iniciar grupo");
}

public void afterPageInit() throws JRScriptletException {
System.out.println("apos iniciar pagina");
}

public void afterReportInit() throws JRScriptletException {
System.out.println("apos iniciar o relatorio");
}

public void beforeColumnInit() throws JRScriptletException {
System.out.println("apos iniciar coluna");
}

public void beforeDetailEval() throws JRScriptletException {
System.out.println("antes fazer a banda detail");
}

public void beforeGroupInit(String arg0) throws JRScriptletException {
System.out.println("antes de iniciar o grupo");
}

public void beforePageInit() throws JRScriptletException {
System.out.println("antes de iniciar a pagina");
}

public void beforeReportInit() throws JRScriptletException {
System.out.println("antes de iniciar o relatorio");
}

}

[As partes desta mensagem que não continham texto foram removidas]

__._,_.___
Para sair da lista, envie email para: java-br-unsubscribe@yahoogroups.com
Para upload/download de arquivos: http://www.yahoogroups.com/files/java-br
.

__,_._,___

0 comentários:

Pague com LPs do Mister Colibri

Pague com LPs do Mister Colibri
Quer comprar celular,Tablet,pen drive, GPS e muito outros produtos e ainda podendo pagar tudo em LPs ?Pois saiba que isso é possível,basta você visitar o site downloadstotal.com e realizar a sua compra com toda tranquilidade e segurança!!!

Hora

Online

Arquivo do Blog