FlowLayout With Gaps

Previous     Next     flgart.java     FLGART.java     Home     Package

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

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

   public FLGART () {
      Toolkit.getDefaultToolkit().setDynamicLayout(true);
      setLayout(new FlowLayout(FlowLayout.LEADING,20,20));
      add(addline = new JButton("One"));
      add(doit = new JButton("Two"));
      add(new JButton("Three"));
      add(new JButton("Four"));
      add(new JScrollPane(text = new JTextArea(10,30)));
      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");
      }
   }
}