// File: BorderLayout3.java import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class BorderLayout3 extends Applet implements ActionListener{ private Button EastButton, SouthButton, CenterButton; public void init() { // instantiating the button objects EastButton = new Button("East"); SouthButton = new Button("South"); CenterButton = new Button("Center"); // add action lisners for all buttons EastButton.addActionListener(this); SouthButton.addActionListener(this); CenterButton.addActionListener(this); /* setting layout to BorderLayout with horizontal and vertical spacing of 10 pixels */ setLayout(new BorderLayout()); // order is not important here as we are specifying the positions add(EastButton,BorderLayout.EAST); add(SouthButton,BorderLayout.SOUTH); add( CenterButton,BorderLayout.CENTER); } public void actionPerformed( ActionEvent e) { Color c=new Color((float)Math.random(),(float)Math.random(),(float)Math.random()); if (e.getSource()==EastButton) EastButton.setBackground( c); else if (e.getSource()==SouthButton) SouthButton.setBackground( c); else if (e.getSource()==CenterButton) CenterButton.setBackground( c); } }