Java Reference
In-Depth Information
public boolean
selected(
int
iXcoord,
int
iYcoord)
{
if
((iXcoord >= x - 10) && (iXcoord <= x + 10)
&& (iYcoord >= y - 10) && (iYcoord <= y + 10))
return true
;
else
return false
;
}
}
public void
init ()
{
addMouseMotionListener(
this
);
myGraph =
new
ColorCircle[NUM_CIRCLES];
for
(
int
i = 0; i < NUM_CIRCLES; i++)
{
ColorCircle myVertex =
new
ColorCircle();
myVertex.setX((
int
)(Math.random() * (WIDTH-50)));
myVertex.setY((
int
)(Math.random() * (HEIGHT - 100)));
myGraph[i] = myVertex;
}
JOptionPane.showMessageDialog(
null
,
"Try to drag any one of the colored circles ",
"Information", JOptionPane.PLAIN_MESSAGE );
}
public void
paint(Graphics g)
{
Color[] myColor = {Color.black, Color.red, Color.blue,
Color.green, Color.cyan,
Color.orange, Color.yellow};
if
(NUM_CIRCLES > 0)
for
(
int
i = 0; i < NUM_CIRCLES; i++)
{
1
2
g.setColor(myColor[i]);
myGraph[i].paint(g);
}
}
public void
mouseDragged(MouseEvent event)
{
int
iX = event.getX();
int
iY = event.getY();
for
(
int
i = 0; i < NUM_CIRCLES; i++)
if
(myGraph[i].selected(iX, iY))
Search WWH ::
Custom Search