BorderLayout With Gaps, TextArea & Reset

Previous     Next     blgart.java     BLGART.java     Home     Package

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

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");
      }
   }
}