1 package com.wsy.work2;
2
3 import java.awt.Color;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6
7 import javax.swing.JButton;
8 import javax.swing.JFrame;
9 import javax.swing.JPanel;
10
11 public class EventProcessing implements ActionListener{
12 JFrame jf;
13 JButton jb;
14 JPanel jp;
15 public EventProcessing()
16 {
17 jf = new JFrame();
18 jb = new JButton("改变背景颜色");
19 jp = new JPanel();
20 jp.add(jb);
21 jp.setBackground(Color.BLUE);
22 jf.add(jp);
23 jf.setSize(300,300);
24 jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
25 jf.setVisible(true);
26 jf.setLocation(100,200);
27 jb.addActionListener(this);
28 }
29 @Override
30 public void actionPerformed(ActionEvent e) {
31 jp.setBackground(Color.PINK);
32 }
33 public static void main(String[] args) {
34 new EventProcessing();
35
36 }
37
38
39
40 }