• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

getting warning compiling this program on j2sdk1.5  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;
import java.applet.Applet;

public class MovingBall extends Applet implements Runnable
{
Thread mythread=null;
int position=0;

public void start()
{
mythread = new Thread(this);
mythread.start();
}

public void run()
{
while (true)
{
for(position=0;position<getSize().width;position += 5)
{
repaint();
try
{
mythread.sleep(1000);
}
catch(InterruptedException e)
{
}
}
}
}

public void stop()
{
mythread.stop();
mythread=null;
}

public void paint(Graphics g)
{
g.setColor(Color.gray);
g.fillOval(position,50,30,30);
g.setColor(Color.black);
g.fillOval(position+6,58,5,5);
g.fillOval(position+20,58,5,5);
g.drawLine(position+15,58,position+15,68);
g.drawLine(position+12,68,position+15,68);
g.drawArc(position,45,30,30,-50,-70);


}
}



After compiling error comes as


I:\java programs\First AWT>javac -Xlint MovingBall.java
MovingBall.java:35: warning: [deprecation] stop() in java.lang.Thread has been d
eprecated
mythread.stop();
^
MovingBall.java:4: warning: [serial] serializable class MovingBall has no definition of serialVersionUID
public class MovingBall extends Applet implements Runnable
^
2 warnings



Please guide me whats this warning
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the first warning: don't call Thread.stop(). Change the "while(true)" in your run() method to be "while(running)", where "running" is a volatile boolean member variable initialized to "true", and change the stop() call to "running = false".

For the second one: this is a truly useless warning, but you could make it go away by adding a member declaration like

private static final long serialVersionUID = 1;

to your Applet class.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!