JInternalFrame是Java Swing的一部分。JInternalFrame是一个容器,提供框架的许多功能,包括显示标题、打开、关闭、调整大小、支持菜单栏等。 JInternalFrame的构造函数
null
- JInternalFrame() :创建一个新的不可关闭、不可调整大小、不可图标化、不可最大化且没有标题的JInternalFrame
- JInternalFrame(t字串) :使用指定的标题创建一个新的不可关闭、不可调整大小、不可图标化、不可最大化的JInternalFrame
- JInternalFrame(字符串t,可调整布尔值大小) :创建一个新的不可关闭、不可图标化、不可最大化的JInternalFrame,并指定标题和大小
- JInternalFrame(字符串t、布尔值可调整大小、布尔值可关闭) :创建一个新的不可图标化、不可最大化的JInternalFrame,并指定标题、可关闭性和可调整大小
- JInternalFrame(字符串t、布尔可调整大小、布尔可关闭、布尔可最大化) :创建一个新的非图标化JInternalFrame,并指定标题、可关闭性、最大化性和可调整大小
- JInternalFrame(字符串t、布尔可调整大小、布尔可关闭、布尔可最大化、布尔可图标化) :创建一个新的JInternalFrame,并指定标题、可关闭性、最大化性、图标化性和可调整大小
常用方法
- setFrameIcon(图标图标) :将框架的图标设置为指定的图像
- setLayout(布局管理器) :将框架的布局设置为指定的布局管理器
- setTitle(字符串t) :将框架的标题设置为指定的标题
- getTitle() :获取框架的标题
- 重塑(整数x,整数y,整数宽度,整数高度) :将框架调整为指定的宽度和高度以及指定的位置
- 增加(c部分) :将指定的组件添加到容器中。
- addImpl(组件c、对象co、int i) :添加指定的组件。
- addInternalFrameListener(InternalFrameListener l) :将指定的InternalFrameListener添加到列表中。
- createRootPane() :由构造函数调用以设置JRootPane。
- 处置 :使此内部框架不可见、未选中和关闭。
- fireInternalFrameEvent(内部id) :触发内部帧事件。
- getAccessibleContext() :获取与此JInternalFrame关联的AccessibleContext。
- getContentPane() :返回此内部框架的内容窗格。
- getDefaultCloseOperation() :返回用户在此内部帧上启动“关闭”时发生的默认操作。
- getDesktopIcon() :返回此JInternalFrame图标化时使用的JDesktopIcon。
- getDesktopPane() :在祖先层次结构中搜索JDesktop实例的便捷方法。
- getFocusOwner() :如果此JInternalFrame处于活动状态,则返回具有焦点的子对象。
- getFrameIcon() :返回此内部框架标题栏中显示的图像
- getGlassPane() :返回此内部框架的玻璃窗格。
- getInternalFrameListeners() :使用addInternalFrameListener返回添加到此JInternalFrame的所有InternalFrameListener的数组
- getJMenuBar() :返回此JInternalFrame的当前JMenuBar
- getLastCursor() :返回setCursor方法设置的最后一个游标
- getLayer() :获取此组件图层属性的便捷方法。
- getLayeredPane() :返回此内部框架的分层窗格。
- getMostRecentFocusOwner() :返回选中此JInternalFrame时将接收焦点的JInternalFrame的子组件。
- getNormalBounds() :如果JInternalFrame未处于最大化状态,则返回getBounds();否则,返回JInternalFrame将恢复到的边界。
- getRootPane() :返回此内部帧的根窗格对象。
- getUI() :返回呈现此组件的外观对象。
- getWarningString() :获取与此内部帧一起显示的警告字符串。
- 不公开的() :返回某个用户操作是否可以关闭此JInternalFrame。
- isClosed() :返回此JInternalFrame当前是否已关闭。
- isIcon() :返回JInternalFrame当前是否已图标化。
- isMaximizable() :获取可最大化属性的值。
- isMaximum() :返回JInternalFrame当前是否最大化。
- isResizable() :返回JInternalFrame是否可以调整大小。
- 选举产生() :返回JInternalFrame是否为当前活动帧。
- 包装() :使此JInternalFrame的组件按其首选尺寸布置。
- 油漆组件(图形g) :重写以允许在拖动内部框架时进行优化绘制。
- paramString() :返回此JInternalFrame的字符串表示形式。
- 拆卸(部件c) :从容器中删除指定的组件。
- removeInternalFrameListener(InternalFrameListener l) :删除指定的内部帧侦听器。
- setClosable(布尔b) :设置此JInternalFrame是否可以通过某些用户操作关闭。
- setContentPane(容器c) :设置此JInternalFrame的contentPane属性。
- 设置光标(光标c) :将光标图像设置为指定的光标。
- setDefaultCloseOperation(int o) :设置当用户在此内部框架上启动“关闭”时默认情况下将发生的操作。
- setDesktopIcon(JInternalFrame.JDesktopIcon d) :设置与此JInternalFrame关联的JDesktopIcon。
- 玻璃材质窗格玻璃(g组分) :设置此JInternalFrame的glassPane属性。
- 设置图标(布尔b) :图标化或反图标化此内部框架。
- setJMenuBar(JMenuBar m) :设置此JInternalFrame的菜单栏属性。
- SetIconnifiable(布尔b) :设置iconable属性,该属性必须为true,用户才能将JInternalFrame设置为图标。
- setJMenuBar(JMenuBar m) :设置此JInternalFrame的菜单栏属性。
- 设置层(int l) :设置此组件图层属性的便捷方法。
- 设置层(整数l) :设置此组件图层属性的便捷方法。
- setLayeredPane(JLayeredPane l) :设置此JInternalFrame的layeredPane属性。
- 可设置最大化(布尔b) :设置maximizable属性,该属性确定JInternalFrame是否可以通过某些用户操作最大化。
- 设置最大值(布尔b) :最大化并恢复此内部帧。
- setNormalBounds(矩形r) :设置此内部帧的法线边界。
- 可设置大小(布尔b) :设置JInternalFrame是否可以通过某些用户操作调整大小。
- setRootPane(JRootPane r) :设置此JInternalFrame的根窗格属性。
- setRootPaneCheckingEnabled(布尔值e) :设置是否将添加和设置布局的调用转发到contentPane。
- 集合选择(布尔s) :选择或取消选择正在显示的内部帧。
- setUI(内部框架ui) :设置此JInternalFrame的UI委托。
- show() :使内部框架可见。
- 托巴克 :将此内部帧发送到背面。
- toFront() :将此内部框架带到前面。
- updateUI() :来自UIManager的外观和感觉已更改的通知。
1.创建简单JInternalFrame的程序:
JAVA
// java Program to create a simple JInternalFrame import java.awt.event.*; import java.awt.*; import javax.swing.*; class solution extends JFrame { // frame static JFrame f; // label to display text static JLabel l; // main class public static void main(String[] args) { // create a new frame to f = new JFrame( "frame" ); // create a internal frame JInternalFrame in = new JInternalFrame(); // set the title of the frame in.setTitle( "InternalFrame" ); // create a Button JButton b = new JButton( "button" ); // create a label to display text l = new JLabel( "This is a JInternal Frame " ); // create a panel JPanel p = new JPanel(); // add label and button to panel p.add(l); p.add(b); // set visibility internal frame in.setVisible( true ); // add panel to internal frame in.add(p); // add internal frame to frame f.add(in); // set the size of frame f.setSize( 300 , 300 ); f.show(); } } |
输出:
2.创建多个内部框架的程序
JAVA
// java Program to create multiple internal frames import java.awt.event.*; import java.awt.*; import javax.swing.*; class solution extends JFrame { // frame static JFrame f; // label to display text static JLabel l, l1; // main class public static void main(String[] args) { // create a new frame f = new JFrame( "frame" ); // set layout of frame f.setLayout( new FlowLayout()); // create a internal frame JInternalFrame in = new JInternalFrame( "frame 1" , true , true , true , true ); // create a internal frame JInternalFrame in1 = new JInternalFrame( "frame 2" , true , true , true , true ); // create a Button JButton b = new JButton( "button" ); JButton b1 = new JButton( "button1" ); // create a label to display text l = new JLabel( "This is a JInternal Frame no 1 " ); l1 = new JLabel( "This is a JInternal Frame no 2 " ); // create a panel JPanel p = new JPanel(); JPanel p1 = new JPanel(); // add label and button to panel p.add(l); p.add(b); p1.add(l1); p1.add(b1); // set visibility internal frame in.setVisible( true ); in1.setVisible( true ); // add panel to internal frame in.add(p); in1.add(p1); // add internal frame to frame f.add(in); f.add(in1); // set the size of frame f.setSize( 300 , 300 ); f.show(); } } |
输出:
3.程序创建多帧并将图标设置为帧
JAVA
// java Program to create multiple frame and set icon to the frame import java.awt.event.*; import java.awt.*; import javax.swing.*; class solution extends JFrame { // frame static JFrame f; // label to display text static JLabel l, l1; // main class public static void main(String[] args) { // create a new frame f = new JFrame( "frame" ); // set layout of frame f.setLayout( new FlowLayout()); // create a internal frame JInternalFrame in = new JInternalFrame( "frame 1" , true , true , true , true ); // create a internal frame JInternalFrame in1 = new JInternalFrame( "frame 2" , true , true , true , true ); // set icon for internal frames in.setFrameIcon( new ImageIcon( "f:/gfg.jpg" )); in1.setFrameIcon( new ImageIcon( "f:/gfg.jpg" )); // create a Button JButton b = new JButton( "button" ); JButton b1 = new JButton( "button1" ); // create a label to display text l = new JLabel( "This is a JInternal Frame no 1 " ); l1 = new JLabel( "This is a JInternal Frame no 2 " ); // create a panel JPanel p = new JPanel(); JPanel p1 = new JPanel(); // add label and button to panel p.add(l); p.add(b); p1.add(l1); p1.add(b1); // set visibility internal frame in.setVisible( true ); in1.setVisible( true ); // add panel to internal frame in.add(p); in1.add(p1); // add internal frame to frame f.add(in); f.add(in1); // set the size of frame f.setSize( 300 , 300 ); f.show(); } } |
输出:
注意:上述程序可能无法在联机编译器中运行,请使用脱机IDE
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END