LAB.ReportCreate.java Source code

Java tutorial

Introduction

Here is the source code for LAB.ReportCreate.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package LAB;

import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.print.PrinterException;
import java.io.FileInputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.text.Document;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

/**
 *
 * @author SACHI
 */
public class ReportCreate extends javax.swing.JFrame {

    /**
     * Creates new form ReportCreate
     */
    public ReportCreate() {
        initComponents();
    }

    public void close() {
        WindowEvent winClosingEvent = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
    }

    public void GetText(String add1, String add2, String add4, String add5) {

    }

    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        contest = new javax.swing.JTextArea();
        ReadDoc = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        Print_info = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setUndecorated(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        contest.setColumns(20);
        contest.setRows(5);
        jScrollPane1.setViewportView(contest);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 61, 910, 540));

        ReadDoc.setText("View Report");
        ReadDoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReadDocActionPerformed(evt);
            }
        });
        getContentPane().add(ReadDoc, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 16, 121, 39));

        jButton1.setText("Back");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 600, 110, 40));

        Print_info.setText("Print Report");
        Print_info.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Print_infoActionPerformed(evt);
            }
        });
        getContentPane().add(Print_info, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 10, -1, 40));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/test2/images/blue.jpg"))); // NOI18N
        jLabel1.setText("jLabel1");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void ReadDocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReadDocActionPerformed
        try {
            JFileChooser s = new JFileChooser();
            s.showOpenDialog(null);
            XWPFDocument d = new XWPFDocument(new FileInputStream(s.getSelectedFile()));
            XWPFWordExtractor extract = new XWPFWordExtractor(d);
            contest.setText(extract.getText());

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Do you want to leave");
        }

    }//GEN-LAST:event_ReadDocActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        close();
        Addreport t = new Addreport();
        t.setVisible(true);

    }//GEN-LAST:event_jButton1ActionPerformed

    private void Print_infoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Print_infoActionPerformed
        try {

            boolean complete = contest.print();

            if (complete) {
                JOptionPane.showMessageDialog(null, "Done Printing", "information",
                        JOptionPane.INFORMATION_MESSAGE);

            } else {

                JOptionPane.showMessageDialog(null, "Printing", "information", JOptionPane.ERROR_MESSAGE);
            }

        } catch (PrinterException e) {

            JOptionPane.showMessageDialog(null, e);

        }

    }//GEN-LAST:event_Print_infoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ReportCreate.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ReportCreate.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ReportCreate.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ReportCreate.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ReportCreate().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Print_info;
    private javax.swing.JButton ReadDoc;
    private javax.swing.JTextArea contest;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}