import java.awt.*;
import java.awt.event.*;
public class ButtonPress extends Frame implements ActionListener {
	Button btnRed, btnBlue;
	ButtonPress() {
		super("AWT Buttons");
			
		// Red Button		
		btnRed = new Button("Red");
		btnRed.setBounds(25, 50, 250, 30);
		btnRed.addActionListener(this);
		this.add(btnRed);

		// Blue Button		
		btnBlue = new Button("Blue");
		btnBlue.setBounds(25, 100, 250, 30);
		btnBlue.addActionListener(this);
		this.add(btnBlue);
	
		// Size of Frame Window		
		this.setSize(300, 160);
		
		this.setLayout(null);
		this.setVisible(true);

		// To close the Window		
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				dispose();
			}
		});
	}		
		
	public void actionPerformed(ActionEvent e){
		if(e.getSource() == btnRed){
			this.setBackground(Color.RED);
		}else{
			this.setBackground(Color.BLUE);
		}
	}
	
	public static void main(String[] args){
		new ButtonPress();
			
	}
}
