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

/**
 * A window with four buttons and a text area.
 */
public class BorderJFrame extends JFrame {
  
  /** North button. */
  JButton b1;
  
  /** South button. */
  JButton b2;
  
  /** East button. */
  JButton b3;
  
  /** West button. */
  JButton b4;
  
  /** Text area, in the center. */
  JTextArea ta;
  
  /**
   * Create four buttons in the north, south, east, and west, and
   * create a 10x20-character text area in the center.
   */
  public BorderJFrame() {
    this("north button", "south button", "east button", "west button");
    ta.setText("Center");
    

    /* The following code would have been OK, but it would
     * mean duplicate code!  Once the second constructor was
     * written, we could modify this one.

    // Create the four buttons and the text area.
    this.b1= new JButton("north button");
    this.b2= new JButton("south button");
    this.b3= new JButton("east button");
    this.b4= new JButton("west button");
    this.ta= new JTextArea("Center", 10, 20); // 10 chars wide, 20 lines high.
    // Add the buttons and the text area to this window.
    Container c= this.getContentPane();
    c.add(this.b1, "North");
    c.add(this.b2, "South");
    c.add(this.b3, "East");
    c.add(this.b4, "West");
    c.add(this.ta, "Center");

     */

  }
  
  public BorderJFrame(String n, String s, String e, String w) {
    // Create the four buttons and the text area.
    this.b1= new JButton(n);
    this.b2= new JButton(s);
    this.b3= new JButton(e);
    this.b4= new JButton(w);
    this.ta= new JTextArea("", 10, 20); // 10 chars wide, 20 lines high.
    
    // Add the buttons and the text area to this window.
    Container c= this.getContentPane();
    c.add(this.b1, "North");
    c.add(this.b2, "South");
    c.add(this.b3, "East");
    c.add(this.b4, "West");
    c.add(this.ta, "Center");
  }
  
  public BorderJFrame(String s) {
    
    Container c= this.getContentPane();
    
    // make & place first button.
    this.b1= new JButton(s.substring(0, s.indexOf(",")));
    c.add(this.b1, s.substring(s.indexOf(",") + 1,
                               s.indexOf("$")));
    
    // make & place second button.
    s = s.substring(s.indexOf("$") + 1);
    this.b2= new JButton(s.substring(0, s.indexOf(",")));
    c.add(this.b2, s.substring(s.indexOf(",") + 1,
                               s.indexOf("$")));
    
    // make & place third button.
    s = s.substring(s.indexOf("$") + 1);
    this.b3= new JButton(s.substring(0, s.indexOf(",")));
    c.add(this.b3, s.substring(s.indexOf(",") + 1,
                               s.indexOf("$")));
    
    // make & place fourth button.
    s = s.substring(s.indexOf("$") + 1);
    this.b4= new JButton(s.substring(0, s.indexOf(",")));
    c.add(this.b4, s.substring(s.indexOf(",") + 1,
                               s.indexOf("$")));
    
    // make & place text area
    s = s.substring(s.indexOf("$") + 1);
    this.ta= new JTextArea(s.substring(0, s.indexOf(",")), 10, 20);
    c.add(this.ta, s.substring(s.indexOf(",") + 1));
    
  }
  
  /**
   * Make a BorderJFrame for testing.
   */
  public static void main(String[] args) {
    BorderJFrame g= new BorderJFrame();
    g.pack();
    g.show();
  }
}
