学习笔记之面向对象编程28(GUI编程之Panel)

来源:互联网 发布:少女漫画软件下载 编辑:程序博客网 时间:2024/05/16 14:57

《1》Panel对象可以看成可以容纳Component的空间;

《2》Panel对象可以拥有自己的布局管理器;

《3》Panel对象拥有从其父类继承来的

setBounds(int x,int y,int width,int height)

setSize(int width,int height)

setLocation(int x,int y)

setBackground(Color  c)

setLayout(Layout Manager mgr)等方法;

《4》Panel的构建方法:

Panel()使用默认的FlowLayout类布局管理器初始化

Panel(LayoutManager   layout)使用指定的布局管理器初始化

举例:

import java.awt.*;public class TestPanel {public static void main(String[] args){Frame f = new Frame("java Frame with Panel");Panel p = new Panel(null);f.setLayout(null);f.setBackground(new Color(0,0,244));f.setBounds(300,300,300,300);p.setBackground(new Color(244,244,255));p.setBounds(200, 200, 200, 200);f.add(p);f.setVisible(true);}}

运行结果:



原创粉丝点击