Results 1 to 6 of 6

Thread: Java Notepad

  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    3

    Default Java Notepad

    As suggested in a previous thread, I have decided to quickly make a Java coded notepad program.

    This code is only about 15 minutes work really excluding the time it took to refresh myself on event handlers.

    It has no save/open functionality yet as this is what I most want to learn and is what will take up most of my time.

    However, is this going right so far?
    Am I right in simply using a JTextArea (In a scroll pane) as the editor?


    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    
    
    class JavaNotepad{
    
        public static void main(String[] args){
            
            JFrame EditorFrame = new JFrame("Java Notepad");
            EditorFrame.setSize(700, 400);
            EditorFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            EditorFrame.setVisible(true);
            
            // Menu bar start
            JMenuBar MenuBar = new JMenuBar();
            EditorFrame.setJMenuBar(MenuBar);
            
            JMenu File = new JMenu("File");
            MenuBar.add(File);
            
            JMenuItem Save = new JMenuItem("Save As...");
            File.add(Save);
            
            JMenuItem Open = new JMenuItem("Open...");
            File.add(Open);
            
            JMenuItem Exit = new JMenuItem("Exit");
            File.add(Exit);
            
            Exit.addActionListener(new ActionListener(){
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.exit(1);
                }
            });    
            //Menu bar end
            
            // Text area start
            JTextArea TextArea = new JTextArea();
            JScrollPane ScrollPane = new JScrollPane(TextArea);
            EditorFrame.add(ScrollPane);
            // Text area end
            
        }
        
        
    }


    Thank you

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Java Notepad

    Quote Originally Posted by kkid View Post
    Am I right in simply using a JTextArea (In a scroll pane) as the editor?
    Sounds ok to me. But you do need to learn and follow the coding conventions: Code Conventions for the Java Programming Language: Contents

    Variable names should start with a lowercase letter.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Java Notepad

    JTextArea is perfect to begin with and for a simple text editor it is more than enough. Just be aware that it can't do any special formatting should you want to add something like having bold text.

    You need some goals here, some requirements to know when you're done. Let me make a few suggestions:

    - add an extra panel which displays the current line and column, plus the total number of characters in the document
    - implement a search & replace dialog
    - implement a 'tabs to spaces' feature
    - implement a word count feature
    - make the editor aware of which type of text file it is by examining the newlines; if it has \r\n newlines, it is a windows text file. If it has \n newlines, it is a linux text file. If it has \r newlines, it is a mac text file.
    - when saving the text file, make sure it preserves the correct newlines
    - ... but give the user the option to override that and choose a specific type of newline

    Now as a sort of practical lab, you can do a little test to "see what happens".

    Assignment: build an application which can generate a text file containing 1gb of lines containing random text. Each line is a 100 characters wide. Now load that 1gb text file using your editor and see what happens!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    3

    Default Re: Java Notepad

    Quote Originally Posted by DarrylBurke View Post
    Sounds ok to me. But you do need to learn and follow the coding conventions: Code Conventions for the Java Programming Language: Contents

    Variable names should start with a lowercase letter.

    db
    I was actually going to ask about this.
    I usually do start variables with lowercase letters but I read something saying that in some cases it is standard convention to start them with uppercase letters. What is this case?

    Quote Originally Posted by gimbal2 View Post
    JTextArea is perfect to begin with and for a simple text editor it is more than enough. Just be aware that it can't do any special formatting should you want to add something like having bold text.

    You need some goals here, some requirements to know when you're done. Let me make a few suggestions:

    - add an extra panel which displays the current line and column, plus the total number of characters in the document
    - implement a search & replace dialog
    - implement a 'tabs to spaces' feature
    - implement a word count feature
    - make the editor aware of which type of text file it is by examining the newlines; if it has \r\n newlines, it is a windows text file. If it has \n newlines, it is a linux text file. If it has \r newlines, it is a mac text file.
    - when saving the text file, make sure it preserves the correct newlines
    - ... but give the user the option to override that and choose a specific type of newline

    Now as a sort of practical lab, you can do a little test to "see what happens".

    Assignment: build an application which can generate a text file containing 1gb of lines containing random text. Each line is a 100 characters wide. Now load that 1gb text file using your editor and see what happens!
    Sounds good to me. Will see what I can do.
    Do you happen to be a teacher?

    Thanks for your help :)

  5. #5
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    112
    Rep Power
    0

    Default Re: Java Notepad

    I think that the uppercase letters used only in constants and in class names..
    now about this :
    Assignment: build an application which can generate a text file containing 1gb of lines containing random text. Each line is a 100 characters wide. Now load that 1gb text file using your editor and see what happens!

    what's it's going to happen? i already have create my own notepad.. but i don't really understand what i should do :P

    my english are not very good.. pls be lenient ;)


    edit: i think that i just figured out
    Last edited by ShadowWalker; 07-29-2013 at 11:33 PM.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Java Notepad

    Quote Originally Posted by kkid View Post
    Do you happen to be a teacher?
    Nope, just someone who has been through "the system" to realize that you can't learn programming in a classroom, you need to do it yourself. Whenever I have to deal with interns I get people who can write code just fine but can't solve any real world problems for the life of them - I train them by giving them increasingly more difficult programs to build that gradually start to touch more real business problems. Little games, a chat program, a simple "game server" with client and a web interface, etc.

    The fact that I started out doing game programming in school was the single reason why I managed to get an IT degree, because before it programming was my least favorite thing to do. I'm on a mission to help people to have the same experiences I did! If that succeeds depends solely on your own capability to experiment and above all: research.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 2
    Last Post: 06-22-2011, 09:39 AM
  2. java program to connect, edit and add info in notepad
    By violently in forum New To Java
    Replies: 2
    Last Post: 01-14-2011, 05:38 AM
  3. Send Keystrokes from Java to Notepad
    By ramyal in forum AWT / Swing
    Replies: 3
    Last Post: 02-18-2010, 06:09 PM
  4. NotePad
    By whosadork in forum New To Java
    Replies: 10
    Last Post: 10-03-2008, 07:44 PM
  5. Creating a notepad application with java
    By Daniel in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •