20-CS-694 Advanced Programming Techniques Spring 2012

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

     Previous      Next      Applet Source      All lectures

Border Layout

Border Layout with no spacing on the left, 20 pixel spacing on the right

import javax.swing.*;
import java.awt.*;
import java.applet.*;

class BorderlayoutAppletFrame extends JFrame {

   public BorderlayoutAppletFrame () {
      setLayout(new GridLayout(1,2,40,40));

      Panel p = new Panel();
      p.setLayout(new BorderLayout());
      p.add("North", new Button("1"));
      p.add("East", new Button("2"));
      p.add("West", new Button("3"));
      p.add("South", new Button("4"));
      p.add("Center", new Button("5"));

      Panel q = new Panel();
      q.setLayout(new BorderLayout(20,20));
      q.add("North", new Button("6"));
      q.add("East", new Button("7"));
      q.add("West", new Button("8"));
      q.add("South", new Button("9"));
      q.add("Center", new Button("0"));

public class BorderlayoutApplet extends Applet {
   public void init () {
      BorderlayoutAppletFrame ff = new BorderlayoutAppletFrame();