Java | Frames

05 min read

Frames:

The two most common windows are those derived front Panel class which is used by applets and those derived from frame class.

The window provided by Panel class does not contain a menubar, title bar, borders and resizing corners. Thus when an applet is executed in a browser, it does not show any border or title, as applets use window provided by the Panel class.

The Frame class inherits Window class. Generally, Window objects cannot be created and hence objects for its subclass Frame, are created. The window provided by the Frame contains menubar, title bar, borders and resizing controls. Also, Frame class can be used to create a window In a stand-alone application.

 

Constructor:

i)Frame()

ii)Frame(String title)

Method of Frame class, to make the frame visible

setVisible(true)

setSize(width,height) —to set the size for the frame window

Unless this method is invoked, a frame will not be visible on the scream.

A Frame class can also be used to create a window in applets, User-defined frame class can also be created by extending the predefined Frame class. Eg., class myframe extends Frame. As Frame is a subclass of components class, it also has paint( ) method.This method can be defined to display the desired contents.

POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error