package com.TT.lesson; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; //Panel可以看成是一个空间,但不能单独存在 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(40,160,35)); //panel设置坐标,相对于frame panel.setBounds(50,50,400,400); panel.setBackground(new Color(193,15,60)); //frame.add(panel) frame.add(panel); frame.setVisible(true); //监听事件,监听窗口关闭事件 System.exit(0) //适配器模式: frame.addWindowListener(new WindowAdapter() { //窗口关闭的时候需要做的事 @Override public void windowClosing(WindowEvent e) { //结束程序 System.exit(0); } }); } }
GUI-面板Panel
最新推荐文章于 2024-08-26 21:48:53 发布