In this java Example, we have created a class named MyFrame that extends the Frame class. The constructor of the MyFrame class contains the statements that constructs the user interface.
FlowLayout layout = new Flowlayout();
sets the layout manager for the container object (i.e. Frame).The layout manager arranges the GUI components in the window i.e. it determines the position and size of all the components in the container. The first statement creates an object of the class Flowlayout. In this layout manager, the components are arranged in the container (i.e. frame) from left to right, then on the next line when there is no more space. The setLayout () method defined in java.awt.Container class used in the second statement sets the new layout manager for the frame. The statements used for creating and setting layout can be combined as follows,
MyFrame frame = new MyFrame();
in the main () method instantiates an object of MyFrame class which invokes the default constructor. This constructor sets the Flowlayout of the frame and adds two buttons using the add () method with labels OK and Cancel into it.
frame.setTitle("Extending Frame Class in Java Example"};
sets the specified argument as the title of the frame. The other statements in the main () method work as usual.
class Myframe extends Frame
FlowLayout layout = new FlowLayout();
Button ok = new Button("OK");
Button cancel = new Button("Cancel");
public static void main(String args)
Myframe frame = new Myframe();
frame.setTitle("Extending Frame Class in Java Example");