import java.awt.*;

class ResizableButton extends Button
{
   private Dimension dim = null;

   public ResizableButton(String str, Dimension dim)
   {
      super(str);

      this.dim = new Dimension(dim);

      resize(dim);
   }

   public void newPreferredSize(Dimension dim)
   {
      this.dim = new Dimension(dim);

      resize(dim);
   }

   public Dimension preferredSize()
   {
      return new Dimension(dim);
   }
}

public class Resizable extends java.applet.Applet
{
   private ResizableButton rb1 = null;
   private ResizableButton rb2 = null;

   public void init()
   {
      setLayout(new FlowLayout());

      setBackground(Color.cyan);

      Dimension dim = new Dimension(85, 30);

      rb1 = new ResizableButton("Click Me", dim);
      rb2 = new ResizableButton("No, Click Me", dim);

      add(rb1);
      add(rb2);
   }

   public Insets insets()
   {
      return new Insets(30, 10, 10, 10);
   }

   public Dimension preferredSize()
   {
      return new Dimension(200, 100);
   }

   public boolean action(Event e, Object arg)
   {
      Dimension dim1 = rb1.preferredSize();
      Dimension dim2 = rb2.preferredSize();

      if (e.target == rb1)
      {
         dim1.width++;
         dim1.height++;
         dim2.width--;
         dim2.height--;
      }
      else if (e.target == rb2)
      {
         dim2.width++;
         dim2.height++;
         dim1.width--;
         dim1.height--;
      }

      if (dim1.width < 1) dim1.width = 1;
      if (dim1.height < 1) dim1.height = 1;
      if (dim2.width < 1) dim2.width = 1;
      if (dim2.height < 1) dim2.height = 1;

      rb1.newPreferredSize(dim1);
      rb2.newPreferredSize(dim2);

      layout();

      return super.action(e, arg);
   }

   public static void main(String [] args)
   {
      Frame fr = new Frame("Resizable Buttons");

      Resizable res = new Resizable();

      res.init();

      fr.add("Center", res);

      fr.pack();
      fr.show();
   }
}
