20-CS-694 Advanced Programming Techniques Spring 2012
Layouts

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

       Previous     Next     Applet Source     All lectures

GridLayout With Gaps

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

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

   public GLGART () {
      Toolkit.getDefaultToolkit().setDynamicLayout(true);
      setLayout(new GridLayout(2,3,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)));
      add(new JButton("Five"));
      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 glgart extends Applet {
   GLGART b;

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

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