Java Programming/Tutorials/Notepad

= Creating a Notepad application = You wouldn't be able to learn Java wholly if you don't practice working on sample programs. Throughout these tutorials we will help you grasp the true workability with Java projects. The first tutorial in the series is that of creating a simple Windows based application that resembles a notepad.

Setting the class structure
To start programming on our example, we need to write down a  that will encapsulate our Notepad application. We begin with a simple class structure that is empty in the beginning and will be filled appropriately afterward.

Defining an entry point

 * For an in-depth study into the structure of entry points, read the section on The Entry Point.

Because we need our class to be executed, we need an entry point to help it execute while it is stand-alone. To do so, we define a  method that would take care of the execution code.

Laying the base for a main frame
The next step is to lay the foundation for a frame on which the Notepad application needs to be executed. For this, we import three generic packages namely ,  and . Now, because we have  package imported in our code, we can safely extend our  class with the  class.

Using the properties of the frame
Using the  method, we try calling the super-class' constructor to access other properties and methods declared in the super-class. The constructor call that we made is an explicit call, that is, we specifically called for it. But, even if we hadn't called the  method, it would implicitly (or automatically) be called.

In the code below, we try to access the methods inherited into the Notepad class in two different ways. Notice the  variable. The variable, as you might have had studied, helps to call the variables that are a part of the class the variable is called within. The  variable used in this example is used to access the  and the methods whilst within the class.

These two methods help in setting the size of the form and then introducing a  event that would dispose or destroy the frame object once the particular form is closed either by clicking the Close button or by pressing Alt+F4.

Whilst in the  method, we initialize and instantiate the Notepad object. Now because we have a Notepad object named with us, we can access public methods from its reference. We use the same object to call the  method. This would be the second way that we can use to access an object's methods and properties.

The code above is enough to display a blank frame that is of 300 pixel width and 300 pixel height aligned at the top-left corner of the desktop screen. Try closing the frame to check if the  code works. It should work! Then for a test, try taking out the method or just comment it to see what happens otherwise.