// File: BorderLayout4.java import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class BorderLayout4 extends Applet implements ActionListener{ private Button EastButton, NorthButton, CenterButton; public void init() { // instantiating the button objects EastButton = new Button("East"); NorthButton = new Button("North"); CenterButton = new Button("Center"); // add action lisners for all buttons EastButton.addActionListener(this); NorthButton.addActionListener(this); CenterButton.addActionListener(this); /* setting layout to BorderLayout with horizontal and vertical spacing of 10 pixels */ setLayout(new BorderLayout(50,100)); // order is not important here as we are specifying the positions add(EastButton,BorderLayout.EAST); add( NorthButton,BorderLayout.NORTH); 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()==NorthButton) NorthButton.setBackground( c); else if (e.getSource()==CenterButton) CenterButton.setBackground( c); } }