Java Swing |内部框架及示例

JInternalFrame是Java Swing的一部分。JInternalFrame是一个容器,提供框架的许多功能,包括显示标题、打开、关闭、调整大小、支持菜单栏等。 JInternalFrame的构造函数

null
  1. JInternalFrame() :创建一个新的不可关闭、不可调整大小、不可图标化、不可最大化且没有标题的JInternalFrame
  2. JInternalFrame(t字串) :使用指定的标题创建一个新的不可关闭、不可调整大小、不可图标化、不可最大化的JInternalFrame
  3. JInternalFrame(字符串t,可调整布尔值大小) :创建一个新的不可关闭、不可图标化、不可最大化的JInternalFrame,并指定标题和大小
  4. JInternalFrame(字符串t、布尔值可调整大小、布尔值可关闭) :创建一个新的不可图标化、不可最大化的JInternalFrame,并指定标题、可关闭性和可调整大小
  5. JInternalFrame(字符串t、布尔可调整大小、布尔可关闭、布尔可最大化) :创建一个新的非图标化JInternalFrame,并指定标题、可关闭性、最大化性和可调整大小
  6. JInternalFrame(字符串t、布尔可调整大小、布尔可关闭、布尔可最大化、布尔可图标化) :创建一个新的JInternalFrame,并指定标题、可关闭性、最大化性、图标化性和可调整大小

常用方法

  1. setFrameIcon(图标图标) :将框架的图标设置为指定的图像
  2. setLayout(布局管理器) :将框架的布局设置为指定的布局管理器
  3. setTitle(字符串t) :将框架的标题设置为指定的标题
  4. getTitle() :获取框架的标题
  5. 重塑(整数x,整数y,整数宽度,整数高度) :将框架调整为指定的宽度和高度以及指定的位置
  6. 增加(c部分) :将指定的组件添加到容器中。
  7. addImpl(组件c、对象co、int i) :添加指定的组件。
  8. addInternalFrameListener(InternalFrameListener l) :将指定的InternalFrameListener添加到列表中。
  9. createRootPane() :由构造函数调用以设置JRootPane。
  10. 处置 :使此内部框架不可见、未选中和关闭。
  11. fireInternalFrameEvent(内部id) :触发内部帧事件。
  12. getAccessibleContext() :获取与此JInternalFrame关联的AccessibleContext。
  13. getContentPane() :返回此内部框架的内容窗格。
  14. getDefaultCloseOperation() :返回用户在此内部帧上启动“关闭”时发生的默认操作。
  15. getDesktopIcon() :返回此JInternalFrame图标化时使用的JDesktopIcon。
  16. getDesktopPane() :在祖先层次结构中搜索JDesktop实例的便捷方法。
  17. getFocusOwner() :如果此JInternalFrame处于活动状态,则返回具有焦点的子对象。
  18. getFrameIcon() :返回此内部框架标题栏中显示的图像
  19. getGlassPane() :返回此内部框架的玻璃窗格。
  20. getInternalFrameListeners() :使用addInternalFrameListener返回添加到此JInternalFrame的所有InternalFrameListener的数组
  21. getJMenuBar() :返回此JInternalFrame的当前JMenuBar
  22. getLastCursor() :返回setCursor方法设置的最后一个游标
  23. getLayer() :获取此组件图层属性的便捷方法。
  24. getLayeredPane() :返回此内部框架的分层窗格。
  25. getMostRecentFocusOwner() :返回选中此JInternalFrame时将接收焦点的JInternalFrame的子组件。
  26. getNormalBounds() :如果JInternalFrame未处于最大化状态,则返回getBounds();否则,返回JInternalFrame将恢复到的边界。
  27. getRootPane() :返回此内部帧的根窗格对象。
  28. getUI() :返回呈现此组件的外观对象。
  29. getWarningString() :获取与此内部帧一起显示的警告字符串。
  30. 不公开的() :返回某个用户操作是否可以关闭此JInternalFrame。
  31. isClosed() :返回此JInternalFrame当前是否已关闭。
  32. isIcon() :返回JInternalFrame当前是否已图标化。
  33. isMaximizable() :获取可最大化属性的值。
  34. isMaximum() :返回JInternalFrame当前是否最大化。
  35. isResizable() :返回JInternalFrame是否可以调整大小。
  36. 选举产生() :返回JInternalFrame是否为当前活动帧。
  37. 包装() :使此JInternalFrame的组件按其首选尺寸布置。
  38. 油漆组件(图形g) :重写以允许在拖动内部框架时进行优化绘制。
  39. paramString() :返回此JInternalFrame的字符串表示形式。
  40. 拆卸(部件c) :从容器中删除指定的组件。
  41. removeInternalFrameListener(InternalFrameListener l) :删除指定的内部帧侦听器。
  42. setClosable(布尔b) :设置此JInternalFrame是否可以通过某些用户操作关闭。
  43. setContentPane(容器c) :设置此JInternalFrame的contentPane属性。
  44. 设置光标(光标c) :将光标图像设置为指定的光标。
  45. setDefaultCloseOperation(int o) :设置当用户在此内部框架上启动“关闭”时默认情况下将发生的操作。
  46. setDesktopIcon(JInternalFrame.JDesktopIcon d) :设置与此JInternalFrame关联的JDesktopIcon。
  47. 玻璃材质窗格玻璃(g组分) :设置此JInternalFrame的glassPane属性。
  48. 设置图标(布尔b) :图标化或反图标化此内部框架。
  49. setJMenuBar(JMenuBar m) :设置此JInternalFrame的菜单栏属性。
  50. SetIconnifiable(布尔b) :设置iconable属性,该属性必须为true,用户才能将JInternalFrame设置为图标。
  51. setJMenuBar(JMenuBar m) :设置此JInternalFrame的菜单栏属性。
  52. 设置层(int l) :设置此组件图层属性的便捷方法。
  53. 设置层(整数l) :设置此组件图层属性的便捷方法。
  54. setLayeredPane(JLayeredPane l) :设置此JInternalFrame的layeredPane属性。
  55. 可设置最大化(布尔b) :设置maximizable属性,该属性确定JInternalFrame是否可以通过某些用户操作最大化。
  56. 设置最大值(布尔b) :最大化并恢复此内部帧。
  57. setNormalBounds(矩形r) :设置此内部帧的法线边界。
  58. 可设置大小(布尔b) :设置JInternalFrame是否可以通过某些用户操作调整大小。
  59. setRootPane(JRootPane r) :设置此JInternalFrame的根窗格属性。
  60. setRootPaneCheckingEnabled(布尔值e) :设置是否将添加和设置布局的调用转发到contentPane。
  61. 集合选择(布尔s) :选择或取消选择正在显示的内部帧。
  62. setUI(内部框架ui) :设置此JInternalFrame的UI委托。
  63. show() :使内部框架可见。
  64. 托巴克 :将此内部帧发送到背面。
  65. toFront() :将此内部框架带到前面。
  66. 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();
}
}


输出:

图片[1]-Java Swing |内部框架及示例-yiteyi-C++库

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();
}
}


输出:

图片[2]-Java Swing |内部框架及示例-yiteyi-C++库

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();
}
}


输出:

图片[3]-Java Swing |内部框架及示例-yiteyi-C++库

注意:上述程序可能无法在联机编译器中运行,请使用脱机IDE

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享