Saturday, August 24, 2013


JFrame is top-level window in Swing package. It is the extended version of Frame in Awt package. Unlike Frame, JFrame has its child container called contentPane in which all non-menu components are placed in. By using JFrame, you can write only a line of code to close the window created by the JFrame by invoking the setDefaultCloseOperation(int operation) method.

JFrame constructors:
creates a new invisible window.
-Frame(String title)
creates anew invisible window with specified title.

Its useful methods:
returns the contentPane object of the window.
-setDefaultCloseOperation(int operation)
sets the defaut close operation of the window.
-setJMenuBar(JMenuBar menu)
sets the menu bar to the window.
-setIconImage(Image img)
sets the image icon of the window.


import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;

class Show extends JFrame{
Show(String title){
setLayout(new FlowLayout());
Image img=Toolkit.getDefaultToolkit().getImage("d:/icon.png");
Container contpane=getContentPane();
//code add components to the content pane

public class JFrameSwing {
public static void main(String[] args){
new Show("JFrame");

JFrame Swing

No comments:

Post a Comment