package eventListener;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class eventListener extends JFrame implements ActionListener{
private JButton btB, btD;
public static void main(String[] args) {
new eventListener();
}
public eventListener() {
	this.setTitle("事件监听练习一自身类作为监听器");
	this.setBounds(100,100,600,600);
	this.setLayout(new FlowLayout());
	btB =new JButton("蓝色");
	btD =new JButton("弹窗");
	
	btB.addActionListener(this);
	btD.addActionListener(this);
	
	this.add(btB);
	this.add(btD);
	
	this.setVisible(true);
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	
}
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==btB) {
			Container c = getContentPane();
			c.setBackground(Color.BLUE);		
		}else if(e.getSource()==btD) {
			JDialog dialog = new JDialog();
			dialog.setBounds(300,300,400,300);
			dialog.setVisible(true);
		}
	
	
}
}

package eventListener;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class eventListener1 extends JFrame{
private JButton btB, btD;
public static void main(String[] args) {
	new eventListener1();
}
public eventListener1(){
	this.setTitle("事件监听练习二内部类处理");
	this.setBounds(100,100,600,600);
	this.setLayout(new FlowLayout());
	btB =new JButton("绿色");
	btD =new JButton("弹窗");
	
	btB.addActionListener(new ColorEventListener());
	btD.addActionListener(new DialogEventListener());
		
	this.add(btB);
	this.add(btD);
		
	this.setVisible(true);
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class ColorEventListener implements ActionListener {
	@Override
	public void actionPerformed(ActionEvent e) {
		Container c = getContentPane();
		c.setBackground(Color.green);
	}
}
class DialogEventListener implements ActionListener{
	@Override
	public void actionPerformed(ActionEvent e) {
		JDialog dialog = new JDialog();
		dialog.setBounds(100,100,300,300);
		dialog.setVisible(true);
	}
}
}

package eventListener;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class eventListener2 extends JFrame {
private JButton btB, btD;
public static void main(String[] args) {
	new eventListener2();
}
public eventListener2(){
	this.setTitle("事件监听练习三匿名内部类处理");
	this.setBounds(100,100,600,600);
	this.setLayout(new FlowLayout());
	btB =new JButton("红色");
	btD =new JButton("弹窗");
	
	btB.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			Container c = getContentPane();
			c.setBackground(Color.red);
		}
	});
	btD.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			JDialog dialog = new JDialog();
			dialog.setBounds(100,100,300,300);
			dialog.setVisible(true);
		}
	});
	
	this.add(btB);
	this.add(btD);
	
	this.setVisible(true);
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}


}