hendra_de5

FrmReportslipglobal.java

Apr 19th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. /*
  7. * FrmReportPerTransaksi.java
  8. *
  9. * Created on Apr 20, 2012, 1:26:29 PM
  10. */
  11.  
  12. package aplikasiglobal;
  13. import java.awt.Dimension;
  14. import java.awt.Toolkit;
  15. import java.sql.*;
  16. import java.io.*;
  17. import java.sql.DriverManager;
  18. import java.util.*;
  19. import javax.swing.JOptionPane;
  20. import net.sf.jasperreports.engine.util.*;
  21. import net.sf.jasperreports.engine.JasperFillManager;
  22. import net.sf.jasperreports.engine.JasperPrint;
  23. import net.sf.jasperreports.engine.JasperReport;
  24. import net.sf.jasperreports.view.JasperViewer;
  25. //import net.sf.jasperreports.components.barbecue.BarbecueFillComponent.fill;
  26. /**
  27. *
  28. * @author bay
  29. */
  30. public class FrmReportslipglobal extends javax.swing.JFrame {
  31. private void makecenter(){
  32. Dimension screenSize =
  33. Toolkit.getDefaultToolkit().getScreenSize();
  34. Dimension frameSize = this.getSize();
  35. if(frameSize.height > screenSize.height){
  36. frameSize.height = screenSize.height;
  37. }
  38. if(frameSize.width > screenSize.width){
  39. frameSize.width = screenSize.width;
  40. }
  41. this.setLocation(
  42. (screenSize.width - frameSize.width)/2,
  43. (screenSize.height - frameSize.height)/2);
  44.  
  45. }
  46.  
  47. /** Creates new form FrmReportPerTransaksi */
  48. public FrmReportslipglobal() {
  49. initComponents();
  50. makecenter();
  51. }
  52.  
  53. /** This method is called from within the constructor to
  54. * initialize the form.
  55. * WARNING: Do NOT modify this code. The content of this method is
  56. * always regenerated by the Form Editor.
  57. */
  58. @SuppressWarnings("unchecked")
  59. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  60. private void initComponents() {
  61.  
  62. txttransaksi = new javax.swing.JTextField();
  63. bPrint = new javax.swing.JButton();
  64. jButton1 = new javax.swing.JButton();
  65. jLabel1 = new javax.swing.JLabel();
  66. jLabel2 = new javax.swing.JLabel();
  67.  
  68. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  69.  
  70. bPrint.setText("Print");
  71. bPrint.addActionListener(new java.awt.event.ActionListener() {
  72. public void actionPerformed(java.awt.event.ActionEvent evt) {
  73. bPrintActionPerformed(evt);
  74. }
  75. });
  76.  
  77. jButton1.setText("Exit");
  78. jButton1.addActionListener(new java.awt.event.ActionListener() {
  79. public void actionPerformed(java.awt.event.ActionEvent evt) {
  80. jButton1ActionPerformed(evt);
  81. }
  82. });
  83.  
  84. jLabel1.setText("Masukkan NIP");
  85.  
  86. jLabel2.setFont(new java.awt.Font("Vani", 1, 13)); // NOI18N
  87. jLabel2.setText("REPORT SLIP GAJI KARYAWAN");
  88.  
  89. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  90. getContentPane().setLayout(layout);
  91. layout.setHorizontalGroup(
  92. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  93. .addGroup(layout.createSequentialGroup()
  94. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  95. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
  96. .addGap(18, 18, 18)
  97. .addComponent(txttransaksi, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
  98. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  99. .addComponent(bPrint)
  100. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  101. .addComponent(jButton1)
  102. .addGap(48, 48, 48))
  103. .addGroup(layout.createSequentialGroup()
  104. .addGap(92, 92, 92)
  105. .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
  106. .addContainerGap(133, Short.MAX_VALUE))
  107. );
  108. layout.setVerticalGroup(
  109. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110. .addGroup(layout.createSequentialGroup()
  111. .addGap(53, 53, 53)
  112. .addComponent(jLabel2)
  113. .addGap(46, 46, 46)
  114. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  115. .addComponent(txttransaksi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  116. .addComponent(bPrint)
  117. .addComponent(jButton1)
  118. .addComponent(jLabel1))
  119. .addContainerGap(50, Short.MAX_VALUE))
  120. );
  121.  
  122. pack();
  123. }// </editor-fold>
  124.  
  125. private void bPrintActionPerformed(java.awt.event.ActionEvent evt) {
  126. // TODO add your handling code here:
  127. try{
  128. String nm_file= "..\\datareport\\reportslipglobal.jasper";
  129. String driver= "com.mysql.jdbc.Driver";
  130. String kon = "jdbc:mysql://localhost:3306/dbglobal";
  131. String user ="root";
  132. String pass ="";
  133.  
  134. if (txttransaksi.getText().length()==0)
  135. {
  136. JOptionPane.showMessageDialog(null,"Kode Transaksi Belum diisi untuk di print","Konfirmasi",JOptionPane.INFORMATION_MESSAGE );
  137. txttransaksi.requestFocus();
  138. return;
  139. }
  140. HashMap parameter = new HashMap();
  141. parameter.put("paranip",txttransaksi.getText());
  142.  
  143. Class.forName(driver);
  144. Connection con = (Connection) DriverManager.getConnection(kon,user,pass);
  145.  
  146. File report_file = new File(nm_file);
  147. JasperReport jasperReport = (JasperReport)JRLoader.loadObject(report_file.getPath());
  148. JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameter,con);
  149.  
  150. JasperViewer.viewReport(jasperPrint,false);
  151. JasperViewer.setDefaultLookAndFeelDecorated(true);
  152. }catch(Exception e){
  153. JOptionPane.showMessageDialog(null,"Data tidak dapat dicetak !"+e);
  154. }
  155. txttransaksi.setText("");
  156.  
  157.  
  158. }
  159.  
  160. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  161. // TODO add your handling code here:
  162. dispose();
  163. }
  164.  
  165. /**
  166. * @param args the command line arguments
  167. */
  168. public static void main(String args[]) {
  169. java.awt.EventQueue.invokeLater(new Runnable() {
  170. public void run() {
  171. new FrmReportslipglobal().setVisible(true);
  172. }
  173. });
  174. }
  175.  
  176. // Variables declaration - do not modify
  177. private javax.swing.JButton bPrint;
  178. private javax.swing.JButton jButton1;
  179. private javax.swing.JLabel jLabel1;
  180. private javax.swing.JLabel jLabel2;
  181. private javax.swing.JTextField txttransaksi;
  182. // End of variables declaration
  183.  
  184. }
Add Comment
Please, Sign In to add comment