setTitle( "Colours2" );
setSize ( 200, 200 );
setLayout( new FlowLayout() );
Button red = new Button( "Red" );
red.setBackground( Color.white );
red.setForeground( Color.black );
Button blue = new Button( "Blue" );
blue.setBackground( Color.white );
blue.setForeground( Color.black );
add( red );
add( blue );
red.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e )
{ setBackground( Color.red );
repaint();
}
});
blue.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e )
{ setBackground( Color.blue );
repaint();
}
});
addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e )
{ System.exit(0);
}
});
setVisible( true );