• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

awt classes

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
}


------------------
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic