1import java.awt.*;
2public class Example2 {
3 Example2()
4 {
5 //Creating Frame
6 Frame fr=new Frame();
7
8 //Creating a label
9 Label lb = new Label("UserId: ");
10
11 //adding label to the frame
12 fr.add(lb);
13
14 //Creating Text Field
15 TextField t = new TextField();
16
17 //adding text field to the frame
18 fr.add(t);
19
20 //setting frame size
21 fr.setSize(500, 300);
22
23 //Setting the layout for the Frame
24 fr.setLayout(new FlowLayout());
25
26 fr.setVisible(true);
27 }
28 public static void main(String args[])
29 {
30 Example2 ex = new Example2();
31 }
32}
1import java.awt.*;
2/* We have extended the Frame class here,
3 * thus our class "SimpleExample" would behave
4 * like a Frame
5 */
6public class SimpleExample extends Frame{
7 SimpleExample(){
8 Button b=new Button("Button!!");
9
10 // setting button position on screen
11 b.setBounds(50,50,50,50);
12
13 //adding button into frame
14 add(b);
15
16 //Setting Frame width and height
17 setSize(500,300);
18
19 //Setting the title of Frame
20 setTitle("This is my First AWT example");
21
22 //Setting the layout for the Frame
23 setLayout(new FlowLayout());
24
25 /* By default frame is not visible so
26 * we are setting the visibility to true
27 * to make it visible.
28 */
29 setVisible(true);
30 }
31 public static void main(String args[]){
32 // Creating the instance of Frame
33 SimpleExample fr=new SimpleExample();
34 }
35}