Java tutorial
/* * 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 Package1; import java.awt.Color; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JOptionPane; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.parser.PdfTextExtractor; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; import Package1.GoogleClasses.*; import javax.swing.filechooser.FileNameExtensionFilter; import database.*; import java.awt.Font; import javax.swing.JTextField; /** * * @author Administrator */ public class MAIN extends javax.swing.JFrame { String dir, open_dir = null; db_functions db = new db_functions(); /** * Creates new form MAIN */ public MAIN() { initComponents(); setLocation(260, 0); Font Arial = new Font("Arial Black", Font.PLAIN, 16); jLabel3.setFont(Arial); jRadioButtonMenuItem4.setSelected(true); db.connection(); jTextPane1.setEditable(false); mouseClicked(); } public void mouseClicked() { MouseListener mouseListener = new MouseAdapter() { Font banglaFont = new Font("Vrinda", Font.PLAIN, 16); public void mouseClicked(MouseEvent e) { String s = "", s1 = ""; if (e.getClickCount() == 2) { s = jTextPane1.getSelectedText(); jLabel3.setText(s); s1 = s.toLowerCase(); String result = db.search_result(s1); if (result == null) { jLabel3.setText(""); jLabel2.setText(""); JOptionPane.showMessageDialog(null, "Word Not Found for " + result, "Warning !!", JOptionPane.PLAIN_MESSAGE); } else { jLabel2.setText(result); jLabel2.setFont(banglaFont); } } } }; jTextPane1.addMouseListener(mouseListener); } public void pdf_reader() { int value = 0; try { PdfReader reader = new PdfReader(dir); int p = reader.getNumberOfPages(); String page = ""; if (p <= 250) { for (int i = 1; i <= p; i++) { if (i == 1) page = page + "\t\n---------------\t\tPage: " + i + "\t\t---------------\n\n\n"; else page = page + "\t\n\n\n---------------\t\tPage: " + i + "\t\t---------------\n\n\n"; page = page + PdfTextExtractor.getTextFromPage(reader, i); value = (i * 100) / p; progressive_status(value); } // jProgressBar1.setValue(value); } else { for (int i = 1; i <= 200; i++) { if (i == 1) page = page + "\t\n---------------\t\tPage: " + i + "\t\t---------------\n\n\n"; else page = page + "\t\n\n\n---------------\t\tPage: " + i + "\t\t---------------\n\n\n"; page = page + PdfTextExtractor.getTextFromPage(reader, i); value = (i * 100) / p; progressive_status(value); } JOptionPane.showMessageDialog(null, "Only 200 Page converted. \n Download pro version for full access. ", "Warning!!", JOptionPane.PLAIN_MESSAGE); } jTextPane1.setText(page); jLabel1.setText("Total Pages: " + p); } catch (IOException ex) { Logger.getLogger(MAIN.class.getName()).log(Level.SEVERE, null, ex); } } public void progressive_status(int value) { jProgressBar1.setValue(value); jProgressBar1.show(); } public void clearAll() { jTextPane1.setText(""); jProgressBar1.setValue(0); jLabel2.setText(""); jLabel3.setText(""); jLabel1.setText(""); } /** * 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() { buttonGroup1 = new javax.swing.ButtonGroup(); Panel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextPane1 = new javax.swing.JTextPane(); jButton1 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jProgressBar1 = new javax.swing.JProgressBar(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jRadioButtonMenuItem4 = new javax.swing.JRadioButtonMenuItem(); jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem(); jRadioButtonMenuItem2 = new javax.swing.JRadioButtonMenuItem(); jRadioButtonMenuItem3 = new javax.swing.JRadioButtonMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); Panel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Converted Texts", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Vrinda", 3, 24), new java.awt.Color(0, 0, 204))); // NOI18N jTextPane1.setFont(new java.awt.Font("Sylfaen", 0, 18)); // NOI18N jScrollPane1.setViewportView(jTextPane1); javax.swing.GroupLayout Panel1Layout = new javax.swing.GroupLayout(Panel1); Panel1.setLayout(Panel1Layout); Panel1Layout.setHorizontalGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(Panel1Layout.createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 620, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); Panel1Layout.setVerticalGroup(Panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(Panel1Layout.createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE) .addContainerGap())); jButton1.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N jButton1.setText("Browse PDF"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jProgressBar1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jProgressBar1.setForeground(new java.awt.Color(255, 51, 51)); jProgressBar1.setAutoscrolls(true); jProgressBar1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); jProgressBar1.setDoubleBuffered(true); jProgressBar1.setStringPainted(true); jLabel2.setFont(new java.awt.Font("SutonnyMJ", 0, 14)); // NOI18N jLabel3.setFont(new java.awt.Font("Arial Black", 0, 11)); // NOI18N jMenu1.setText("File"); jMenuItem1.setText("Save"); jMenu1.add(jMenuItem1); jMenuItem2.setText("Close"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu1.add(jMenuItem2); jMenuBar1.add(jMenu1); jMenu2.setText("Settings"); buttonGroup1.add(jRadioButtonMenuItem4); jRadioButtonMenuItem4.setText("Default"); jRadioButtonMenuItem4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButtonMenuItem4ActionPerformed(evt); } }); jMenu2.add(jRadioButtonMenuItem4); buttonGroup1.add(jRadioButtonMenuItem1); jRadioButtonMenuItem1.setSelected(true); jRadioButtonMenuItem1.setText("Virinda "); jRadioButtonMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButtonMenuItem1ActionPerformed(evt); } }); jMenu2.add(jRadioButtonMenuItem1); buttonGroup1.add(jRadioButtonMenuItem2); jRadioButtonMenuItem2.setText("SutonyMJ "); jRadioButtonMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButtonMenuItem2ActionPerformed(evt); } }); jMenu2.add(jRadioButtonMenuItem2); buttonGroup1.add(jRadioButtonMenuItem3); jRadioButtonMenuItem3.setText("Times New Roman"); jRadioButtonMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButtonMenuItem3ActionPerformed(evt); } }); jMenu2.add(jRadioButtonMenuItem3); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(53, 53, 53) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(49, 49, 49).addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(Panel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(58, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(23, 23, 23).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(10, 10, 10).addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Panel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(10, 10, 10))); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed clearAll(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Files", "pdf"); if (open_dir != null) { JFileChooser jfilechooser = new JFileChooser(open_dir); jfilechooser.setFileFilter(filter); jfilechooser.showOpenDialog(null); File f = jfilechooser.getSelectedFile(); String path = f.getAbsolutePath(); dir = path; open_dir = dir; pdf_reader(); } else { JFileChooser jfilechooser = new JFileChooser(".//"); jfilechooser.setFileFilter(filter); jfilechooser.showOpenDialog(null); File f = jfilechooser.getSelectedFile(); String path = f.getAbsolutePath(); dir = path; open_dir = dir; pdf_reader(); } }//GEN-LAST:event_jButton1ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed // TODO add your handling code here: System.exit(0); }//GEN-LAST:event_jMenuItem2ActionPerformed private void jRadioButtonMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem1ActionPerformed // TODO add your handling code here: if (jRadioButtonMenuItem1.isSelected()) { Font Vrinda = new Font("Vrinda", Font.PLAIN, 18); jTextPane1.setFont(Vrinda); } }//GEN-LAST:event_jRadioButtonMenuItem1ActionPerformed private void jRadioButtonMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem2ActionPerformed // TODO add your handling code here: Font SutonnyMJ = new Font("SutonnyMJ", Font.PLAIN, 18); jTextPane1.setFont(SutonnyMJ); }//GEN-LAST:event_jRadioButtonMenuItem2ActionPerformed private void jRadioButtonMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem3ActionPerformed Font roman = new Font("Times New Roman", Font.PLAIN, 18); jTextPane1.setFont(roman); }//GEN-LAST:event_jRadioButtonMenuItem3ActionPerformed private void jRadioButtonMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem4ActionPerformed // TODO add your handling code here: Font Sylfaen = new Font("Sylfaen", Font.PLAIN, 18); jTextPane1.setFont(Sylfaen); }//GEN-LAST:event_jRadioButtonMenuItem4ActionPerformed /** * @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(MAIN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MAIN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MAIN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MAIN.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 MAIN().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel Panel1; private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JProgressBar jProgressBar1; private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1; private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem2; private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem3; private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextPane jTextPane1; // End of variables declaration//GEN-END:variables }