MASON-INTEREST-L Archives

June 2010

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Proportional Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Tue, 29 Jun 2010 10:09:20 -0400
MIME-version:
1.0 (Apple Message framework v936)
Reply-To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Content-type:
text/plain; charset=US-ASCII; format=flowed; delsp=yes
Subject:
From:
Sean Luke <[log in to unmask]>
In-Reply-To:
Content-transfer-encoding:
7bit
Parts/Attachments:
text/plain (62 lines)
getResource expects that robot.jpg be located *right next* to the  
class file for the Java class on which getClass() is being called.   
Are you sure it's there?  Eclipse moves class files to its own  
repository.

Sean

On Jun 28, 2010, at 11:04 PM, recent:[log in to unmask] wrote:

> 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();
> g.drawImage(i,0,0,i.getWidth(null),i.getHeight(null),null);
> g.dispose();
> 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(FlockersWithUI.java:118)
> at sim.display.Console.<init>(Console.java:981)
> at groupSize.FlockersWithUI.main(FlockersWithUI.java:24)
>
>
> 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.
> Sean

ATOM RSS1 RSS2