Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
- */
- package com.bijon.saha;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class FileInputOutput extends javax.swing.JFrame {
- public FileInputOutput()
- {
- initComponents();
- this.setTitle("বিজনের নোটপ্যাড ");
- this.setLocationRelativeTo(null);
- }
- /**
- * 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">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- openButton = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- textArea = new javax.swing.JTextArea();
- saveButton = new javax.swing.JButton();
- fileName = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- openButton.setText("Open...");
- openButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- openButtonActionPerformed(evt);
- }
- });
- textArea.setColumns(20);
- textArea.setRows(5);
- jScrollPane1.setViewportView(textArea);
- saveButton.setText("Save");
- saveButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- saveButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(15, 15, 15)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(saveButton)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(fileName)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(openButton))
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(15, 15, 15))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(16, 16, 16)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(openButton, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
- .addComponent(fileName))
- .addGap(7, 7, 7)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(saveButton, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE))
- );
- getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 370, 270));
- pack();
- }// </editor-fold>
- private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String fName = fileName.getText();
- File file = new File(fName);
- try {
- BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
- String content = "";
- String temp;
- while((temp=in.readLine())!=null){
- content+=temp;
- content+="\n";
- }
- textArea.setText(content);
- in.close();
- } catch (FileNotFoundException ex) {
- Logger.getLogger(FileInputOutput.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(FileInputOutput.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String fName = fileName.getText();
- File file = new File(fName);
- try {
- String text = textArea.getText();
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
- out.write(text);
- out.close();
- } catch (FileNotFoundException ex) {
- Logger.getLogger(FileInputOutput.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(FileInputOutput.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * @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(FileInputOutput.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(FileInputOutput.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(FileInputOutput.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(FileInputOutput.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(() -> {
- new FileInputOutput().setVisible(true);
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JTextField fileName;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JButton openButton;
- private javax.swing.JButton saveButton;
- private javax.swing.JTextArea textArea;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement