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

COMPUTER SOFTWARE APPLICATION - CITS



           TASK 4: Creating a TextField, Label and Button component on the Frame
            import java.awt.*;


           class TextExample {



               // initializing using constructor
               TextExample() {


                   // creating a Frame

                   Frame f = new Frame();


                   // creating a Label
                   Label l = new Label(“Employee id:”);



                   // creating a Button
                   Button b = new Button(“Submit”);
                  // creating a TextField
                   TextField t = new TextField();



                   // setting position of above components in the frame
                   l.setBounds(20, 80, 80, 30);
                   t.setBounds(20, 110, 90, 40);
                   b.setBounds(200, 120, 90, 30);



               // adding components into frame
                   f.add(b);
                   f.add(l);
                   f.add(t);



                   // frame size 400 width and 300 height
                   f.setSize(400, 300);


                   // setting the title of frame

                   f.setTitle(“Employee info”);


                   // no layout
                   f.setLayout(null);



                   // setting visibility of frame
                   f.setVisible(true);


                                                           194

                              CITS : IT & ITES - Computer Software Application - Exercise 116
   204   205   206   207   208   209   210   211   212   213   214