Need Concept Help for a game

OK, I'm wanting to make one of those games where you have a big matrix of circles, and if you click on one that'd adjacent to 2 or more of it's same color, you can remove it. I'm wondering what object I should use for those circles. I'm thinking I could use a JButton with a gif icon, or maybe use an Ellipse somehow. What I don't know is what objects I can use so that I can monitor whether my mouse is over it or whether I'm clicking it or something else. Advice from the more experienced would be appreciated. Thanks!

[534 byte] By [Malohkana] at [2007-9-29 6:16:27]
# 1
JButton will let you handle clicks and change the display from 0's to blanks. Does testing for mouse-over matter, or just mouse clicks?
outlander78a at 2007-7-14 20:23:42 > top of Java-index,Other Topics,Java Game Development...
# 2
mouse-over is important too. So with the JButton "icon" deal, can I give it a transparent gif and make it invisible?
Malohkana at 2007-7-14 20:23:42 > top of Java-index,Other Topics,Java Game Development...
# 3

it's never a good idea to use swing components in a game. It's much faster to draw the circles yourself. Here's an example of using an Ellipse for your circles:

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

// <applet code="Circles.class" width="400" height="400"></applet>

public class Circles extends Applet implements MouseMotionListener {

Ellipse2D.Float e[];

Image buffer;

int w,h,x,y;

public void init() {

circles(20,20,20);

w = getSize().width;

h = getSize().height;

buffer = createImage(w,h);

x = -1;

y = -1;

addMouseMotionListener(this);

}

protected void circles(int col,int row,int size) {

e = new Ellipse2D.Float[row*col];

int j,n,x = 0;

for (j = 0;j < col;j++) {

for (n = 0;n < row;n++) {

e[x++] = new Ellipse2D.Float(j*size,n*size,size,size);

}

}

}

public void mouseMoved(MouseEvent e) {

x = e.getX();

y = e.getY();

repaint();

}

public void mouseDragged(MouseEvent e) {

mouseMoved(e);

}

public void paint(Graphics g) {

Graphics2D gfx = (Graphics2D)buffer.getGraphics();

gfx.setColor(Color.white);

gfx.fillRect(0,0,w,h);

gfx.setColor(Color.black);

for (int j = 0;j < e.length;j++) {

if (e[j].contains(x,y)) gfx.fill(e[j]);

else gfx.draw(e[j]);

}

g.drawImage(buffer,0,0,null);

}

public void update(Graphics g) {

paint(g);

}

}

Woogleya at 2007-7-14 20:23:42 > top of Java-index,Other Topics,Java Game Development...
# 4
Advice noted, thanks, and yeah that code is perfect. Dunno why I never thought of implementing the mouse listener. Perfect, thanks so much :)
Malohkana at 2007-7-14 20:23:42 > top of Java-index,Other Topics,Java Game Development...