JApplet, ImageIcon class in javax.swing: Types of constructors, Methods

JApplet class: JApplet class in javax.swing provides a Swing version of an Applet. It extends an Applet class by providing new components like glass pane, content pane, and root pane.

Methods defined by JApplet class:

getContentPane( ) method: It is used to get the content pane.


Container getContentPane( )

add( ) method: It is used to add a component.


void add(com)

ImageIcon class: ImageIcon class is used to wrap an icon javax.swing. It is used to create an icon from an image and it implements Icon interface.

Constructors defined by ImageIcon class:

By using filename of image:

ImageIcon(String filename)

By using URL of image:

ImageIcon(URL url)

Methods defined by ImageIcon class:

getIconHeight( ) method: It is used to return height of icon in pixels.


int getIconHeight( )

getIconWidth( ) method: It is used to return width of icon in pixels.


int getIconWidth( )

paintIcon( ) method: It is used to paint icon are coordinates x, y on graphics context g. com is used to enter additional info about paint.


void paintIcon(Component com, Graphics g, int x, int y)

Leave a Reply