• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

awt classes

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me what is wrong with the mouseDown() method of the following code. While compilation it gives a warning as "java uses or overrides a deprecated API".
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Event;
public class spots extends java.applet.Applet
{
final int MAXSPOTS = 10;
int xspots[] = new int[MAXSPOTS];
int yspots[] = new int[MAXSPOTS];
int currspots = 0;
public void init()
{
setBackground(Color.white);
}
public boolean mouseDown(Event evt, int x, int y)
{
if ( currspots < MAXSPOTS )
{
addspot(x,y);
return true;
}
else
{
System.out.println("Too many spots");
return false;
}
}
void addspot(int x, int y)
{
xspots[currspots] = x;
yspots[currspots] = y;
currspots++;
repaint();
}

public void paint(Graphics g)
{
g.setColor(Color.blue);
for( int i = 0; i < currspots; i++)
{
g.fillOval(xspots[i] - 10,yspots[i] -10,20,20);
}
}
}


------------------
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's part of the old event model, deprecated since 1.1. It's slow, and poorly supported now. You probably want to add a MouseListener intead. Sun's Java Tutorial has examples here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic