Posted by: Java_help April 22, 2011
IT -- Solutions Center[Forum]
Login in to Rate this Post:     0       ?        

package pingpong;

import java.awt.*;
/*
 *
 * field
 *
 */
class field
{

 int x_pos, y_pos, width, height;
 Graphics g;

 field (int x, int y, int w, int h)
 {
  x_pos = x;
  y_pos = y;
  width = w;
  height = h;

 }

 void setGraphics (Graphics gr)
 {
  g = gr;
 }

  void draw ()
  {
   int x, y;

   //g.setColor(Color.green);
   //for (x = 0; x < width; x += 10)
  // g.drawLine(x, 0, x, height);
   //g.setColor(Color.red);
   //for (y = 0; y < height; y += 10)
  // g.drawLine(0, y, width, y);
     //g.setColor(Color.black);

    g.fillRect( 0, 0, width, 10);
   g.fillRect(0, 0, 10, height);
   g.fillRect(0, height - 10, width, height);

  }

  void erase ()
  {
   g.setColor(Color.white);
   draw();
     g.setColor(Color.black);

  }
  void move (int x, int y)
  {
  
   x_pos = x;
   y_pos = y;
  
  }

}

 

Read Full Discussion Thread for this article