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.
- */
- /*
- * FrmReportPerTransaksi.java
- *
- * Created on Apr 20, 2012, 1:26:29 PM
- */
- package aplikasiglobal;
- import java.awt.Dimension;
- import java.awt.Toolkit;
- import java.sql.*;
- import java.io.*;
- import java.sql.DriverManager;
- import java.util.*;
- import javax.swing.JOptionPane;
- import net.sf.jasperreports.engine.util.*;
- import net.sf.jasperreports.engine.JasperFillManager;
- import net.sf.jasperreports.engine.JasperPrint;
- import net.sf.jasperreports.engine.JasperReport;
- import net.sf.jasperreports.view.JasperViewer;
- //import net.sf.jasperreports.components.barbecue.BarbecueFillComponent.fill;
- /**
- *
- * @author bay
- */
- public class FrmReportslipglobal extends javax.swing.JFrame {
- 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 FrmReportPerTransaksi */
- public FrmReportslipglobal() {
- initComponents();
- 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() {
- txttransaksi = new javax.swing.JTextField();
- bPrint = new javax.swing.JButton();
- jButton1 = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- bPrint.setText("Print");
- bPrint.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- bPrintActionPerformed(evt);
- }
- });
- jButton1.setText("Exit");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jLabel1.setText("Masukkan NIP");
- jLabel2.setFont(new java.awt.Font("Vani", 1, 13)); // NOI18N
- jLabel2.setText("REPORT SLIP GAJI KARYAWAN");
- 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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(txttransaksi, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(bPrint)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton1)
- .addGap(48, 48, 48))
- .addGroup(layout.createSequentialGroup()
- .addGap(92, 92, 92)
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(133, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(53, 53, 53)
- .addComponent(jLabel2)
- .addGap(46, 46, 46)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(txttransaksi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(bPrint)
- .addComponent(jButton1)
- .addComponent(jLabel1))
- .addContainerGap(50, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void bPrintActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try{
- String nm_file= "..\\datareport\\reportslipglobal.jasper";
- String driver= "com.mysql.jdbc.Driver";
- String kon = "jdbc:mysql://localhost:3306/dbglobal";
- String user ="root";
- String pass ="";
- if (txttransaksi.getText().length()==0)
- {
- JOptionPane.showMessageDialog(null,"Kode Transaksi Belum diisi untuk di print","Konfirmasi",JOptionPane.INFORMATION_MESSAGE );
- txttransaksi.requestFocus();
- return;
- }
- HashMap parameter = new HashMap();
- parameter.put("paranip",txttransaksi.getText());
- Class.forName(driver);
- Connection con = (Connection) DriverManager.getConnection(kon,user,pass);
- File report_file = new File(nm_file);
- JasperReport jasperReport = (JasperReport)JRLoader.loadObject(report_file.getPath());
- JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameter,con);
- JasperViewer.viewReport(jasperPrint,false);
- JasperViewer.setDefaultLookAndFeelDecorated(true);
- }catch(Exception e){
- JOptionPane.showMessageDialog(null,"Data tidak dapat dicetak !"+e);
- }
- txttransaksi.setText("");
- }
- private void jButton1ActionPerformed(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 FrmReportslipglobal().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton bPrint;
- private javax.swing.JButton jButton1;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JTextField txttransaksi;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment