import java.awt.*;
import javax.swing.JFrame;
import java.awt.event.*;
public class VentanaEvento extends JFrame
{
Button Boton = new Button("ON - OFF");
Panel Fondo = new Panel();
boolean Verde = false;
public VentanaEvento()
{
this.getContentPane().setLayout(null);
this.setTitle("Topicos de la animacion");
this.setResizable(false);
this.setLocation(100, 100);
this.setSize(new Dimension(600, 350));
Fondo.setBounds(0, 0, 600, 350);
this.add(Fondo);
Boton.setBounds(50, 50, 100, 50);
Fondo.add(Boton);
Boton.addActionListener(new Evento());
this.setVisible(true);
}
public static void main(String R[])
{
new VentanaEvento();
}
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
class Evento implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (Verde)
{
Fondo.setBackground(Color.blue);
Verde = false;
}
else
{
Fondo.setBackground(Color.green);
Verde = true;
}
}
}
}