学习画板

画板可以看成是一个空间,但是不能单独存在

 

 实习代码:

public class TestPanel {

public static void main(String[] args) {
Frame frame = new Frame();
//布局的概念
Panel panel = new Panel();


//设置布局,默认置顶
frame.setLayout(null);


//设置坐标

frame.setBounds(300,300,500,500);
frame.setBackground(new Color(199, 199, 29));

//panel设置坐标,相对于frame
panel.setBounds(50,50,400,400);
panel.setBackground(new Color(222, 12, 12));

//frame.add(panel)
frame.add(panel);
//设置可见性
frame.setVisible(true);
frame.setResizable(false);

//监听事件,监听窗口关闭事件 System.exit(0)
//适配器模式:
frame.addWindowListener(new WindowAdapter() {
//窗口点击关闭的时候需要做的事情
@Override
public void windowClosing(WindowEvent e) {
//结束程序
System.exit(0);
}
});

}
}
posted @ 2021-12-12 17:07  tuyin  阅读(40)  评论(0)    收藏  举报