skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Saturday, September 15, 2012

Extraction of content from Notepad to Excel in a alinged manner

Posted by Admin at 1:03 AM – 0 comments
 

This Java Program helps in extracting the content form Notepad to Excel in a clear and alinged format


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.File;
import java.util.*;


public class DemoJFileChooserF extends JPanel
   implements ActionListener {
   JButton go;
   JTextField go1;
   JComboBox go2;
   JFileChooser chooser;
   String choosertitle;

  public DemoJFileChooserF() {
    go = new JButton("Start");
    go1 = new JTextField(10);

  
   go2.addActionListener(this);
    go1.addActionListener(this);
    go.addActionListener(this);
    add(go);
    add(go1);
  
   }

  public void actionPerformed(ActionEvent e) {
    int result;

    chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle(choosertitle);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    //
    // disable the "All files" option.
    //
    chooser.setAcceptAllFileFilterUsed(false);
    //
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
      //System.out.println("getCurrentDirectory(): "+  chooser.getCurrentDirectory());
       File curFolder = chooser.getSelectedFile();
         File[] listofFiles = curFolder.listFiles();
         if (listofFiles == null) {
        // Either dir does not exist or is not a directory
         }
         else {
             System.out.println("List Of Files......................");
             for (int i=0; i<listofFiles.length; i++) {
            // Get filename of file or directory
                    System.out.println(listofFiles[i].toString());
                    FileReadF.report(listofFiles[i].toString());
        }
 }
      
       
        System.out.println("getSelectedFile() : " +  chooser.getSelectedFile());
        System.out.println(go1.getText());
        System.out.println(go2.getSelectedItem());
      }
      else {
        System.out.println("No Selection ");
      }
     }

     public Dimension getPreferredSize(){
        return new Dimension(200, 200);
     }

    public static void main(String s[]) {
        JFrame frame = new JFrame("");
        DemoJFileChooserF panel = new DemoJFileChooserF();
        frame.addWindowListener(
        new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
        System.exit(0);
          }
      }
      );
    frame.getContentPane().add(panel,"Center");
    frame.setSize(panel.getPreferredSize());
    frame.setVisible(true);
    }
}

Labels: Excel Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger