Monday, March 16, 2009

Swing Objects

The JFrame class

JFrame class was a object class imported from javax.swing package.Its also represents a framed window and considered as a parent container.

JFrame class hierarchy:

Frame, Window, Container, Component, and finally Object).



Container
In instantiating the container you will just type the Container class

and a getContentPane() method.See the code below



Container pane=getContentPane();


pane was the object variable of the container class an d it will inherit the Container class. The Container class will carry all the components that you add to your window through using the

add() method. The container should be layout through the layout manager by using the setLayout()method. to know more about container click here.

Important methods of the JFrame:

setSize(int,int) this method will set the size of your frame on your desired size.
setTitle(String) this method will set the title of your window
setVisible(boolean) this method will set your window to be visible if the boolean is true.


Here are some code for making a frame or Window




//*****************

import java.awt.*;
import javax.swing.*;


public class SampleFrame extends JFrame{


public SampleFrame (){

}

public static void main (String args[]){
SampleFrame frame=new SampleFrame ();
frame.setSize(300,400);
frame.setTitle("View Test(shown 1times)");
frame.setVisible(true);
}

}



sample output below:










No comments:

Post a Comment