Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * FrmReportCatalog.java
- *
- * Created on Dec 3, 2011, 7:20:45 AM
- */
- package aplikasiglobal;
- import com.mysql.jdbc.Connection;
- import java.awt.Dimension;
- import java.awt.Toolkit;
- import java.sql.DriverManager;
- import java.util.HashMap;
- import koneksi.SettingUI;
- import net.sf.jasperreports.engine.*;
- import net.sf.jasperreports.view.JasperViewer;
- /**
- *
- * @author qq
- */
- public class FrmReportGaji extends javax.swing.JFrame {
- private Connection koneksi;
- private String ReportPath="report/";
- private SettingUI config=
- new SettingUI(null, true);
- private void initConnection(){
- config.setServer("localhost");
- config.setUser("root");
- config.setPassword("");
- config.setDatabase("dbglobal");
- config.makeConnect();
- }
- private void buildReport(String vName){
- String reportSource;
- String reportDest;
- reportSource=ReportPath+
- "templates/" + vName + ".jrxml";
- reportDest=ReportPath+
- "result/" + vName + ".pdf";
- try{
- JasperReport jasperReport =
- JasperCompileManager.compileReport(reportSource);
- JasperPrint jasperPrint =
- JasperFillManager.fillReport(jasperReport,null,
- config.getConnection());
- JasperExportManager.exportReportToPdfFile(jasperPrint,reportDest);
- JasperViewer.viewReport(jasperPrint,false);
- }
- catch (JRException ex){
- ex.printStackTrace();
- }
- }
- private void makecenter(){
- Dimension screenSize =
- Toolkit.getDefaultToolkit().getScreenSize();
- Dimension frameSize = this.getSize();
- if(frameSize.height > screenSize.height){
- frameSize.height = screenSize.height;
- }
- if(frameSize.width > screenSize.width){
- frameSize.width = screenSize.width;
- }
- this.setLocation(
- (screenSize.width - frameSize.width)/2,
- (screenSize.height - frameSize.height)/2);
- }
- /** Creates new form FrmReportCatalog */
- public FrmReportGaji() {
- initComponents();
- initConnection();
- makecenter();
- }
- /** 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() {
- jLabel1 = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jLabel1.setText("LAPORAN ABSENSI KARYAWAN");
- jButton1.setText("Print Report");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Exit");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(114, 114, 114)
- .addComponent(jButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton2))
- .addGroup(layout.createSequentialGroup()
- .addGap(88, 88, 88)
- .addComponent(jLabel1)))
- .addContainerGap(86, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(46, 46, 46)
- .addComponent(jLabel1)
- .addGap(55, 55, 55)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap(52, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- ReportDefault("../DATAREPORT/reportabsenglobal.jrxml");
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- dispose();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new FrmReportGaji().setVisible(true);
- }
- });
- }
- public void ReportDefault(String sourcefilename) {
- try {
- JasperReport report;
- report = JasperCompileManager.compileReport(sourcefilename);
- JasperPrint jprint = JasperFillManager.fillReport(report,
- new HashMap(), connect());
- JasperViewer viewer = new JasperViewer(jprint, false);
- viewer.setFitPageZoomRatio();
- viewer.setVisible(true);
- } catch (Exception e) {
- System.out.print(e.getMessage());
- }
- }
- private Connection connect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- koneksi = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/dbglobal", "root", "");
- }
- catch (Exception ex)
- {
- System.out.println(ex.getMessage());
- }
- return koneksi;
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment