Today, early in the morning I made my first notepad clone… with less options and solutions !
So today I am going to show you ! How to make a less of a notepad in java !

Packages we will need

The class

Base variables.

Our JTextArea will be the area where you can write documents and etc…
Also if you are unfamiliar with JFileChooser, then try to read more about the swing lib in Javas API page. Also by changed it will represent our flag of when things in our area changes.

Constructor Part #1
So here we are our area and the toolbar we will use… with JScrollPane we will be able to view a bit more of our text and area…Most likely as anything else :>
Constructor Part #2
Now by adding methods and arguments we haven’t implemented from the beginning will of course complain in an active IDE…However fear not we will come to the point what New/Open/Save/Quit/SaveAs are…
While adding we also position them in a correct order with our for loop and set every icon to null.
Constructor Part #3
We are currently adding our functions and giving some proper icons for our toolbar items ! Note we are adding in icons and giving null text to each item.
Our Save and SaveAs functions will represent the standard every time we launch the application…hence it’s false…

Now here we have our listener which will listen when any key is pressed thus making the changed statement true and allowing us to save or saveas.Quite good right?

Action #1
By pressing on our ItemIcon we will trigger an Action(Abstract one). Also by triggering the Icon action we will be able to preserve the moment of our text. Resulting us to be able choose where to save and use it later :>

Action #2
So here is our save function. We will be able to save our current file. So by playing along I thought like this. If the currentFile doesn’t equal to Untitled then just save it as it’s called… else save as thus allowing the sure to give it a title 😛

Action #3
Nothing much with this action. We are just allowing the user to saveAs…thus giving it a title…

Action #4
A quit function is needed also we are saving the old one. Which means… we will see later on 😛

Action Maping
By allowing us, to give absolute correct power we are using the DefaultEditorKit in the Swing package…(IO too..)

Methods #1
So now we have defined what saveFileAs will result to. However what will saveFile do, is something I will return to.

Methods #2
By using a saveOld giving us an option to save the changed state thus naming it old doesn’t seem wrong, right~?

Method #3
As we are allowed to save, how do we open a file? Easy making a filereader method… The beep sound isn’t required however I feel that making it kinda “cooler” why not give it an extra touch?

Method #4
Our savefile method. Allowing the user to define a name for the title as well to his/her document. 

The main
Creating a new TextEditor everytime we launch !

Read more:

What Do You Think on This ? Say Here