狂神说 javaweb 26集:监听器GUI中的理解
监听器:GUI编程中经常使用;
package com.study.listener;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestPanel {
public static void main(String[] args) {
Frame frame = new Frame( "中秋节快乐" );//新建一个窗体
Panel panel = new Panel( null );//面板
frame.setLayout( null );//设置窗体的布局
frame.setBounds( 300,300,500,500 );
frame.setBackground( new Color( 0,0,255 ) );
panel.setBounds( 50,50,300,300 );
panel.setBackground( new Color( 0,255,0 ) );
frame.add( panel );
frame.setVisible( true );
//监听事件,监听关闭事件
frame.addWindowListener( new WindowAdapter() {