Page 204 - CTS - CSA TP - Volume 2
P. 204

COMPUTER SOFTWARE APPLICATION - CITS



           public static void main(String[] args) {
           // Create an instance of SimpleContainer, passing the desired title
                   SimpleContainer simpleContainer = new SimpleContainer(“Simple Container Example”);

               }
           }
           1  Import necessary classes:








           These lines import the Frame and Label classes from the java.awt package, which are used for creating graphical
           user interface components.
           2  Define the class SimpleContainer:






           This line declares a class named SimpleContainer that extends the Frame class. This means that SimpleContainer
           is a subclass of Frame and inherits its properties and methods.
           3   Constructor of SimpleContainer class:





           This line begins the constructor of the SimpleContainer class. The constructor is a special method that is called
           when an instance of the class is created. It takes a String parameter title to set the title of the frame.
           4  Call the superclass constructor:







           This line calls the constructor of the superclass (Frame) with the provided title. It sets the title of the frame.
           5  Create a label:





           This line creates a new Label component with the specified text.

           6  Add the label to the frame:





           This line adds the created label to the frame. It places the label inside the frame.
           7  Set the size of the frame:






            This line sets the size of the frame to 300 pixels in width and 200 pixels in height.


                                                           189

                              CITS : IT & ITES - Computer Software Application - Exercise 116
   199   200   201   202   203   204   205   206   207   208   209