Component作为基类,提供了如下常用的方法来设置组件的大小、位置、可见性等。
| 方法签名 | 方法功能 |
| setLocation(int x,int y) | 设置组件的位置 |
| setSize(int width,int heigth) | 设置组件的大小 |
| setBounds(int x,int y,int width,int heigth) | 设置组件的位置,大小。 |
| setVisible(Boolean b) | 设置该组件的可见性 |
Container作为容器根类,提供了如下方法来访问容器中的组件
| 方法签名 | 方法功能 |
| Component add(Compinent comp) | 向容器中添加其他组件(该组件既可以是普通组件,也可以是容器),并返回被添加的组件 |
| Component getComponentAt(int x,int y): | 返回指定点的组件 |
| int getComponentCount(): | 返回该容器内组件的数量 |
| Component[] getComponents(): | 返回该容器内的所有组件 |
package com.aynu.container;
import java.awt.*;
public class WindowDemo {
public static void main(String[] args) {
//创建一个窗口对象
Frame frame=new Frame("这里测试Window窗口");
//指定窗口的位置,大小
frame.setLocation(100,100);
frame.setSize(500,300);
//设置窗口对象可见
frame.setVisible(true);
}
}

Panel容器:
package com.aynu.container;
import javax.swing.*;
import java.awt.*;
public class PanelDemo {
public static void main(String[] args) {
//1.创建一个Window对象,因为Panel以及其他的容器,都不能独立存在,必须依附于window存在
Frame frame=new Frame("这里演示Panel");
//2.创建一个Panel对象
Panel p =new Panel();
//3.创建一个文本框和一个按钮,并且把他们放入到Panel容器中
p.add(new TextField("这里是一个测试文本"));
p.add(new JButton("这里是一个测试按钮"));
//4.把panel放入到Window中
frame.add(p);
//5.设置window的位置以及大小
frame.setBounds(100,100,500,300);
//6.设置window可见
frame.setVisible(true);
}
}

ScorllPane
package com.aynu.container;
import javax.swing.*;
import java.awt.*;
public class ScorllPaneDemo {
public static void main(String[] args) {
Frame frame=new Frame("这里演示ScrollPane");
//1.创建一个ScrollPane对象
ScrollPane sp =new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
//2.往ScrollPane中添加内容
sp.add(new TextField("这是测试文本"));
sp.add(new JButton("这是测试按钮"));
//3.把ScrollPane添加到window中
frame.add(sp);
frame.setBounds(100,100,500,300);
frame.setVisible(true);
}
}









![[元来学NVMe协议] NVMe IO 指令集(NVM 指令集)| Flush 命令](https://img-blog.csdnimg.cn/2a1deab996d84659969c3d4596b3ea3e.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAenp6euasog==,size_20,color_FFFFFF,t_70,g_se,x_16)










