java - Remove fillRect rectangles -


i trying make simple game have squares of random size , color appear @ random location on screen , have click on them. more click higher score.

i have working except, have no idea how make when click on square disappears.

here rectangle code

g.fillrect(cube.cubeposx, cube.cubeposy, cube.cubesize, cube.cubesize); 

the position, size, , color predetermined , randomly selected in class file.

suggestions:

  • don't hard code rectangles you're drawing.
  • instead create collection of rectangles such arraylist<rectangle> drawn in loop in paintcomponent(...) method of drawing jpanel.
  • then remove them arraylist when user clicks on them.
  • this done in mouselistener , again uses loop,
  • but key being loop iterates backwards. reason rectangles on "top" of others last ones drawn. should first ones removed if clicked on.
  • you call repaint() on drawing jpanel (or jcomponent) after removing rectangle.

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -