事件处理

package com.wsy.work;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class EventProcessing implements ActionListener{
JFrame jf;
JButton jb;
JPanel jp;
public EventProcessing()
{
jf = new JFrame();
jb = new JButton("改变背景颜色");
jp = new JPanel();
jp.add(jb);
jp.setBackground(Color.BLUE);
jf.add(jp);
jf.setSize(300,300);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.setLocation(100,200);
jb.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
jp.setBackground(Color.PINK);
}
public static void main(String[] args) {
new EventProcessing();

}

 

}

posted @ 2019-05-15 22:08  尹天仇,  阅读(199)  评论(0编辑  收藏  举报