my code stock.com

simple notepad program

Snippet options

Download: Download snippet as notepad.java.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package notepad;


import java.awt.*;
import java.awt.GridLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.Buffer;
import javax.swing.*;
import org.omg.CORBA.SystemException;


/**
 *
 * @author Mcit
 */
public class Main extends JFrame  {

        String file_Path;

        JLabel fileName;
        JLabel no_Of_Characters;
        JLabel no_Of_Lines;

        JLabel fileName_Value;
        JLabel no_Of_Characters_Value;
        JLabel no_Of_Lines_Value;

        JTextArea textrea;

        JScrollBar main_ScrollBar;

        JPanel text;
        JPanel status_A;

        JScrollPane main;

        JMenuBar menu_Body;
        JMenu menu_Co;
        JMenuItem open;
        JMenuItem save;
        JMenuItem exit;

    /**
     * @param args the command line arguments
     */
        public Main(){
            
            fileName = new JLabel("File Name");
            no_Of_Characters = new JLabel("no. of characters");
            no_Of_Lines = new JLabel("no. of lines");
            
            fileName_Value = new JLabel();
            no_Of_Characters_Value = new JLabel();
            no_Of_Lines_Value = new JLabel();
            
            textrea = new JTextArea();
            
            main_ScrollBar = new JScrollBar();
            
            text = new JPanel();

            status_A = new JPanel();
            status_A.setLayout(new GridLayout(3,2));

            main = new JScrollPane(textrea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            setLayout(new BorderLayout());

            menu_Body = new JMenuBar();
            menu_Co = new JMenu("File");
            open = new JMenuItem("Open");
            save = new JMenuItem("Save");
            exit = new JMenuItem("Exit");

            open.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JFileChooser brow;
                String a;
                String all_cont="";
                brow = new JFileChooser();
                brow.showOpenDialog(null);
                file_Path = brow.getSelectedFile().getPath();
                try
                {
                BufferedReader b =new BufferedReader(new FileReader(file_Path));
                a="";
                while ( (a = b.readLine()) != null ){
                    all_cont += a + "\r\n";
                    }
                textrea.setText(all_cont);
                }
                catch (FileNotFoundException ex)
                {
                    System.out.println("Error" + ex.getMessage());
                }
                catch (IOException ex)
                {
                    System.out.println("Error" + ex.getMessage());
                }
            }
        });
            

            menu_Co.add(open);
            menu_Co.add(save);
            menu_Co.add(exit);

            menu_Body.add(menu_Co);
            
            
            add(main, BorderLayout.CENTER);

            status_A.add(fileName);
            status_A.add(no_Of_Characters);
            status_A.add(no_Of_Lines);
            status_A.add(fileName_Value);
            status_A.add(no_Of_Characters_Value);
            status_A.add(no_Of_Lines_Value);
            add(status_A,BorderLayout.SOUTH);

            setJMenuBar(menu_Body);
            setSize(800, 600);
            setTitle("notepad");
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
            public static void main(String[] args) {
                new Main();

        // TODO code application logic here
    }
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.