aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes awt classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "awt classes" Watch "awt classes" New topic
Author

awt classes

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: awt classes