//********************************************************************

// buttons.java

//********************************************************************



import java.awt.*;

import java.util.*;



//********************************************************************



class button_info extends Object

  {

    public String s;

    public int x;

    public int y;

    public int w;

    public int h;



    public button_info(String s, int x, int y, int w, int h)

      {

        this.s = s;

        this.x = x;

        this.y = y;

        this.w = w;

        this.h = h;

      }

  }



//********************************************************************



public class buttons

  {

    static Graphics g;

    static boolean first_time = true;

    static int total_buttons = 0;



    static Vector coordinate;



    static FontMetrics font_metrics;



    static int point_size = 20;

    static int baseline =  0;



    //----------------------------------------------------------------



    public buttons(Graphics g, String s, int x, int y, int w, int h)

      {

        if (first_time)

          {

            first_time = false;

            this.g = g;



            Font font = new Font("TimesRoman", Font.BOLD, point_size);

            g.setFont(font);

            font_metrics = g.getFontMetrics();

            baseline = font_metrics.getAscent();



            coordinate = new Vector();

          }



        total_buttons++;

        coordinate.addElement(new button_info(s, x, y, w, h));

        draw_items();

      }



    //----------------------------------------------------------------



    static void draw_items()

      {

        for (int i = 0; i < total_buttons; i++)

          {

            button_info b = (button_info) coordinate.elementAt(i);



            g.setColor(Color.cyan);

            g.fillRect(b.x, b.y, b.w, b.h);



            g.setColor(Color.blue);

            g.drawString(b.s, b.x, b.y + baseline - 1);



            g.setColor(Color.white);

            g.drawRect(b.x, b.y, b.w, b.h);

          }

      }



    //----------------------------------------------------------------



    static int push_button(int x, int y)

      {

        for (int i = 0; i < total_buttons; i++)

          {

            button_info b = (button_info) coordinate.elementAt(i);



            if (x > b.x && x < b.x + b.w &&

                y > b.y && y < b.y + b.h)

              {

                g.setColor(Color.black);

                g.fillRect(b.x, b.y, b.w, point_size);

                g.setColor(Color.white);

                g.drawString(b.s, b.x, b.y + baseline);



                return (i);

              }

          }



        return (-1);

      }

  }

