BorderLayout With Gaps, TextArea & Reset

Prev      Next      Applet Source     All lectures

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

public class BLGART extends JFrame implements ActionListener {
   JButton doit, addline;
   JTextArea text;
   int i;

   public BLGART () {
      Toolkit.getDefaultToolkit().setDynamicLayout(true);
      setLayout(new BorderLayout(20,20));
      add("North",addline = new JButton("North"));
      add("South",doit = new JButton("South"));
      add("East",new JButton("East"));
      add("West",new JButton("West"));
      add("Center",new JScrollPane(text = new JTextArea()));
      doit.addActionListener(this);
      addline.addActionListener(this);
      i=1;
   }

   public void actionPerformed (ActionEvent evt) {
      if (evt.getSource() == doit) {
	 text.setText("");
	 while ( i < 50 ) 
	    text.append("Now is the "+(i++)+"th time to aid the party\n");
      } else if (evt.getSource() == addline) {
	 text.append("Now is the "+(i++)+"th time to aid the party\n");
      }
   }
}

public class blgart extends Applet {
   BLGART b;

   public void init () {
      b = new BLGART();
      b.setSize(600,600);
      b.setVisible(true);
   }

   public void finalize () {  b.dispose();  }
}