Skip to main content

Text File Viewer - Netbeans Java Codes


Java Code:

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFileChooser;
class MyCustomFilter extends javax.swing.filechooser.FileFilter {
    
    
 public boolean accept(File file){
        return file.isDirectory()|| 
                file.getAbsolutePath().endsWith(".txt");
                }
    @Override
    public String getDescription() {
        return "Video File (*.txt)";
    }
        }

private void MenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // [Find More Java Codes at www.sumikuma.tk]
        int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION){
            File file = fileChooser.getSelectedFile();
            try {
                textarea.read(new FileReader(file.getAbsolutePath()),null);
                        } catch (IOException ex) {
                            System.out.println("problem accessing file"+ file.getAbsolutePath());
                        }
        }else {
            System.out.println("File access cancelled by user.");
        }
    }                                         

    private void ExitActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // Find More Java Codes at www.sumikuma.tk
        System.exit(0);
    } 
[Find More Java Codes at www.sumikuma.tk]

You can also download text file of this code here:  TxtViewer.txt

Comments

Popular posts from this blog

Javax Code for Playing Music:

Javax Code for Playing Music: OUTPUT: ________________________________________________________________ Just Copy and Paste and Change the variable name respectively: ________________________________________________________________ ________________________________________________________________ Buttons: 1. jButton1 : Open Music File 2. jButton2 : Play 3, jButton3 : Stop 4. jButton4 : Pause ________________________________________________________________ import java.io.File;     import java.io.IOException;     import java.net. MalformedURLException;     import javax.sound.sampled. AudioInputStream;     import javax.sound.sampled. AudioSystem;     import javax.sound.sampled.Clip;     import javax.sound.sampled. LineUnavailableException;     import javax.sound.sampled. UnsupportedAudioFileException; public class Music extends javax.swing.JFrame {     /** ...

Get Current System Time & Date - Netbeans Java Code

Run Shot of Current System Time & Date Java Code: import java.text.SimpleDateFormat; import java.util.Date; public class Datetimemonth { public static void main(String[] args) { Date now = new Date(); System.out.println("toString(): " + now); // dow mon dd hh:mm:ss zzz yyyy // SimpleDateFormat can be used to control the date/time display format: // E (day of week): 3E or fewer (in text xxx), >3E (in full text) // M (month): M (in number), MM (in number with leading zero) // 3M: (in text xxx), >3M: (in full text full) // h (hour): h, hh (with leading zero) // m (minute) // s (second) // a (AM/PM) // H (hour in 0 to 23) // z (time zone) SimpleDateFormat dateFormatter = new SimpleDateFormat("E, y-M-d 'at' h:m:s a z"); System.out.println("Format 1: " + dateFormatter.format(now)); dateFormatter = new Sim...

Get Pascal's Triangle - Netbeans Java Codes

Run-Shot of Pascal's Triangle Java Code: public class Pascalstriangle { public static void main(String args[]) { int x = 6; int triangle[][] = new int[x][x]; for (int i = 0; i < x; i++) { for (int j = 0; j < x; j++) { triangle[i][j] = 0; } } for(int i = 0; i < x; i++) { triangle[i][0] = 1 ; } for (int i = 1; i < x; i++) { for (int j = 1; j < x; j++) { triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j]; } } for (int i = 0; i < x; i++) { for(int j=0;j<=i;j++) { System.out.print(triangle[i][j]+ " "); } System.out.println(); } } } [Find more Netbeans Java Code at www.sumikuma.tk] You can also download text file version of this code: Pascal-triangle_javacode.txt