What is internal frame? Write a program that displays an internal frame within some parent frame.
Internal frame is a frame that is inside another frame. The JInternalFrame class is used to display a JFrame-like window within another window. Usually, we add internal frames to a desktop pane. The desktop pane, in turn, might be used as the content pane of a JFrame. The desktop pane is an instance of JDesktopPane, which is a subclass of JLayeredPane that has added API for managing multiple overlapping internal frames.
In the program below, we are just displaying five frames inside another frame.
//MyInternalFrame.java
import javax.swing.*;
public class MyInternalFrame extends JFrame {
public MyInternalFrame() {
for(int i=0; i<5; i++) {
JInternalFrame frame = new JInternalFrame("Internal Frame" + i);
frame.setLocation(i*50+10, i*50+10);
frame.setSize(200, 150);
this.add(frame);
frame.setVisible(true);
}
setVisible(true);
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MyInternalFrame();
}
}
Comments
Post a Comment