Yes I checked the docs/howto.html file about how to draw a background.
According to this doc, I use the following code:
Display2D display;
Image i = new ImageIcon(getClass().getResource("robot.jpg")).getImage();
BufferedImage b = display.getGraphicsConfiguration().createCompatibleImage(i.getWidth(null), i.getHeight(null));
Graphics g = b.getGraphics();
display.setBackdrop(new TexturePaint(b, new Rectangle(0,0,i.getWidth(null),i.getHeight(null))));
But Eclipse indicates there are errors:
Exception in thread "main" java.lang.NullPointerException
at groupSize.FlockersWithUI.init(
at sim.display.Console.<init>(
at groupSize.FlockersWithUI.main(
Line 118 is:
BufferedImage b = display.getGraphicsConfiguration().createCompatibleImage(i.getWidth(null), i.getHeight(null));
I think I have put robot.jpg in the bin folder.
But I don't know why there is a NullPointerException.

From: Sean Luke <[log in to unmask]>
To: MASON-INTEREST-L <[log in to unmask]>
Time: 2010-06-22  17:04:42
Carbon Copy: <>
Subject: Re: How to use the code in the app "Flockers"?
On Jun 20, 2010, at 5:40 PM, recent:[log in to unmask] wrote:
> 1) In the app "Flockers", how should I revise the code so that I can  
> change the colorful triangle to a png file which is provided by  
> myself?
No sweat.  Check out sim.portrayal.simple.ImagePortrayal2D.  You'd  
register that portrayal in the ContinuousPortrayal2D instead of the  
Flockers drawing themselves.  If this terminology is confusing, check  
out the MASON tutorials.  See MASON's tutorial 5 in particular.
> 2) In the app "Flockers", how should I revise the code so that I can  
> change the black background to a jpg file which is provided by myself?
Also straightforward.  Check out the docs/howto.html file, which has a  
number of items along these lines.