hendra_de5

FrmReportGaji.java

Apr 19th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.04 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. * FrmReportCatalog.java
  8. *
  9. * Created on Dec 3, 2011, 7:20:45 AM
  10. */
  11.  
  12. package aplikasiglobal;
  13.  
  14. import com.mysql.jdbc.Connection;
  15. import java.awt.Dimension;
  16. import java.awt.Toolkit;
  17. import java.sql.DriverManager;
  18. import java.util.HashMap;
  19. import koneksi.SettingUI;
  20. import net.sf.jasperreports.engine.*;
  21. import net.sf.jasperreports.view.JasperViewer;
  22.  
  23.  
  24. /**
  25. *
  26. * @author qq
  27. */
  28. public class FrmReportGaji extends javax.swing.JFrame {
  29. private Connection koneksi;
  30. private String ReportPath="report/";
  31. private SettingUI config=
  32. new SettingUI(null, true);
  33.  
  34. private void initConnection(){
  35. config.setServer("localhost");
  36. config.setUser("root");
  37. config.setPassword("");
  38. config.setDatabase("dbglobal");
  39. config.makeConnect();
  40. }
  41.  
  42. private void buildReport(String vName){
  43. String reportSource;
  44. String reportDest;
  45.  
  46. reportSource=ReportPath+
  47. "templates/" + vName + ".jrxml";
  48. reportDest=ReportPath+
  49. "result/" + vName + ".pdf";
  50.  
  51. try{
  52. JasperReport jasperReport =
  53. JasperCompileManager.compileReport(reportSource);
  54. JasperPrint jasperPrint =
  55. JasperFillManager.fillReport(jasperReport,null,
  56. config.getConnection());
  57. JasperExportManager.exportReportToPdfFile(jasperPrint,reportDest);
  58. JasperViewer.viewReport(jasperPrint,false);
  59. }
  60. catch (JRException ex){
  61. ex.printStackTrace();
  62. }
  63. }
  64.  
  65. private void makecenter(){
  66. Dimension screenSize =
  67. Toolkit.getDefaultToolkit().getScreenSize();
  68. Dimension frameSize = this.getSize();
  69. if(frameSize.height > screenSize.height){
  70. frameSize.height = screenSize.height;
  71. }
  72. if(frameSize.width > screenSize.width){
  73. frameSize.width = screenSize.width;
  74. }
  75. this.setLocation(
  76. (screenSize.width - frameSize.width)/2,
  77. (screenSize.height - frameSize.height)/2);
  78. }
  79. /** Creates new form FrmReportCatalog */
  80. public FrmReportGaji() {
  81. initComponents();
  82. initConnection();
  83. makecenter();
  84. }
  85.  
  86. /** This method is called from within the constructor to
  87. * initialize the form.
  88. * WARNING: Do NOT modify this code. The content of this method is
  89. * always regenerated by the Form Editor.
  90. */
  91. @SuppressWarnings("unchecked")
  92. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  93. private void initComponents() {
  94.  
  95. jLabel1 = new javax.swing.JLabel();
  96. jButton1 = new javax.swing.JButton();
  97. jButton2 = new javax.swing.JButton();
  98.  
  99. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  100.  
  101. jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  102. jLabel1.setText("LAPORAN ABSENSI KARYAWAN");
  103.  
  104. jButton1.setText("Print Report");
  105. jButton1.addActionListener(new java.awt.event.ActionListener() {
  106. public void actionPerformed(java.awt.event.ActionEvent evt) {
  107. jButton1ActionPerformed(evt);
  108. }
  109. });
  110.  
  111. jButton2.setText("Exit");
  112. jButton2.addActionListener(new java.awt.event.ActionListener() {
  113. public void actionPerformed(java.awt.event.ActionEvent evt) {
  114. jButton2ActionPerformed(evt);
  115. }
  116. });
  117.  
  118. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  119. getContentPane().setLayout(layout);
  120. layout.setHorizontalGroup(
  121. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  122. .addGroup(layout.createSequentialGroup()
  123. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  124. .addGroup(layout.createSequentialGroup()
  125. .addGap(114, 114, 114)
  126. .addComponent(jButton1)
  127. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  128. .addComponent(jButton2))
  129. .addGroup(layout.createSequentialGroup()
  130. .addGap(88, 88, 88)
  131. .addComponent(jLabel1)))
  132. .addContainerGap(86, Short.MAX_VALUE))
  133. );
  134. layout.setVerticalGroup(
  135. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  136. .addGroup(layout.createSequentialGroup()
  137. .addGap(46, 46, 46)
  138. .addComponent(jLabel1)
  139. .addGap(55, 55, 55)
  140. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  141. .addComponent(jButton1)
  142. .addComponent(jButton2))
  143. .addContainerGap(52, Short.MAX_VALUE))
  144. );
  145.  
  146. pack();
  147. }// </editor-fold>
  148.  
  149. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  150. // TODO add your handling code here:
  151. ReportDefault("../DATAREPORT/reportabsenglobal.jrxml");
  152. }
  153.  
  154. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  155. // TODO add your handling code here:
  156. dispose();
  157. }
  158.  
  159. /**
  160. * @param args the command line arguments
  161. */
  162. public static void main(String args[]) {
  163. java.awt.EventQueue.invokeLater(new Runnable() {
  164. public void run() {
  165. new FrmReportGaji().setVisible(true);
  166. }
  167. });
  168. }
  169. public void ReportDefault(String sourcefilename) {
  170. try {
  171. JasperReport report;
  172. report = JasperCompileManager.compileReport(sourcefilename);
  173. JasperPrint jprint = JasperFillManager.fillReport(report,
  174. new HashMap(), connect());
  175. JasperViewer viewer = new JasperViewer(jprint, false);
  176. viewer.setFitPageZoomRatio();
  177. viewer.setVisible(true);
  178. } catch (Exception e) {
  179. System.out.print(e.getMessage());
  180. }
  181. }
  182.  
  183.  
  184. private Connection connect() {
  185. try {
  186. Class.forName("com.mysql.jdbc.Driver");
  187. koneksi = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/dbglobal", "root", "");
  188. }
  189. catch (Exception ex)
  190. {
  191. System.out.println(ex.getMessage());
  192. }
  193.  
  194. return koneksi;
  195. }
  196. // Variables declaration - do not modify
  197. private javax.swing.JButton jButton1;
  198. private javax.swing.JButton jButton2;
  199. private javax.swing.JLabel jLabel1;
  200. // End of variables declaration
  201.  
  202. }
Add Comment
Please, Sign In to add comment