my code stock.com

simple notepad program

Snippet-Optionen

Download: Snippet als notepad.java herunterladen.
Snippet kopieren: Für diese Aktion benötigst du einen kostenlosen my code stock.com Account
Embed-Code : Du findest den Embed-Code für dieses Snippet am Ende der Seite, wenn du es in eine Webseite oder einen Blog einbinden möchtest!

/*
 * 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
    }
}

Jetzt kostenlosen my code stock.com Account anlegen

my code stok.com ist ein kostenloser Dienst zum Speichern und Verwalten von Code-Snippets jeglicher Art und Programmiersprache. Wir bieten dir viele Vorteile für die tägliche Arbeit mit Code-Snippets und der gemeinsamen Arbeit im Team, probier es aus!

Jetzt informieren und registrieren

Du kannst die Höhe des iFrame-Codes beliebig anpassen! Mehr Infos findest du in unserer Embed-Code API Referenz.