What is the use of Frame class in java?
Hi All,
I just started to study the class concepts of java programming language. For me the core java was not too much complicated. But I am totally confused about the 'Frame class'. I am able to get the exact use of this java programming class. If anyone has good knowledge about the Frame class, then please let me aware about that. If possible then please give suitable example for 'Frame class'.
Re: What is the use of Frame class in java?
A Frame class is a top-level window with a title and a border. The size of the frame includes any area designated for the border. The dimensions of the border area may be obtained using the getInsets method, however, since these dimensions are platform-dependent, a valid insets value cannot be obtained until the frame is made displayable by either calling pack or show. Since the border area is included in the overall size of the frame, the border effectively obscures a portion of the frame.
Re: What is the use of Frame class in java?
Hi friend,
Following example will definitely give you idea about the 'Frame class':
Code:
java.awt.Frame
import java.awt.event.WindowEvent;
public class FrameDM extends JFrame {
public CenteredFrame() {
setTitle("CenteredFrame");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
Toolkit tk1 = Toolkit.getDefaultToolkit();
Dimension screenSize1 = tk.getScreenSize();
int screenHeight1 = screenSize.height;
int screenWidth1 = screenSize.width;
setSize(screenWidth1 / 2, screenHeight1 / 2);
setLocation(screenWidth1 / 4, screenHeight1 / 4);
}
public static void main(String[] arpgs) {
FrameDM frame1 = new CenteredFrame();
frame1.show();
}
}
Re: What is the use of Frame class in java?
I suggest you to go through the following methods of Frame class:
- setUndecorated(boolean bl)
- setTitle(String ttle)
- setState(int state1)
- setResizable(boolean bl)
- setMenuBar(MenuBar mbr)
- setMaximizedBounds(Rectangle bnd)
Re: What is the use of Frame class in java?
Example of Frame class of java:
Code:
import java.awt.event.WindowAdapter;
java.awt.Frame
public class FrameSample extends JFrame
{
public CloseFrameAction()
{
setTitle("CloseableFrame");
setSize(350, 200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
}
public static void main(String[] ardgs) {
FrameSample frameB = new CloseFrameAction();
frameB.show();
}
}
Re: What is the use of Frame class in java?
Hello friend,
Review following nested classes of Frame class, which are useful to access it's properties:
- Frame.AccessibleAWTFrame
- Component.BltBufferStrategy
- Window.AccessibleAWTWindow
- Component.AccessibleAWTComponent
- Container.AccessibleAWTContainer