【Java AWT 图形界面编程】Container 容器 ① ( Container 容器类子类 | Component 组件类常用 API | Container 容器类常用 API )

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6


文章目录

  • ​​一、Container 容器类子类​​
  • ​​二、Container 容器常用 API​​






一、Container 容器类子类



Container 容器类 , 继承自 Component 组件类

public class Container extends Component



Container 容器类 又有如下几个子类 : 这些容器类子类也都是容器 , 都有一个 默认的 布局管理器 ;

  • Window 窗口容器 : 该类有如下 2 个子类 , Frame 和 Dialog , 默认的 布局管理器 是 BorderLayout ;
  • Frame 是窗口类 ;
  • Dialog 是对话框类 ;
  • Panel 内嵌容器 : 该类有一个子类 Applet 类 , 默认的 布局管理器 是 FlowLayout ;
  • ScrollPanel 可滚动容器 : 默认的 布局管理器 是 BorderLayout ;





二、Container 容器常用 API



Container 容器类 是 Component 组件类 的子类 , 因此 Container 中也可以调用 Component 中的函数



Component 组件类 常用 API :

  • setLocation(int x, int y) : 设置 组件 在 屏幕中的位置
  • setSize(int width, int height) : 设置 组件 大小
  • setBounds(int x, int y, int width, int height) : 同时设置 组件 在屏幕中的位置 和 组件 像素大小 ;
  • setVisible(boolean b) : 设置组件是否可见


Container 容器类 常用 API :

  • Component add(Component c) : 向 Container 容器 中 添加 Component 组件 实例对象 , 返回被添加的组件 ; 注意 Container 是 Component 的子类 , 因此 此处也可以添加 Container 容器 ;
  • Component getComponentAt(int x, int y) : 返回指定 屏幕坐标 位置的组件 ;
  • int getComponentCount() : 获取 Container 容器 中的 Component 组件个数 ;
  • Component[] getComponent() : 获取 Container 容器中的所有 Component 组件 ;


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: Java

“【Java AWT 图形界面编程】Container 容器 ① ( Container 容器类子类 | Component 组件类常用 API | Container 容器类常用 API )” 的相关文章