2010/12/8 Greg Brown <[email protected]>
> Ah, I see. You are calling ButtonData#setIcon(String) with that value. That
> method obtains the location of the image as relative to the classpath, so
> the leading "/" is required.
>
When using Pivot 1.5.2 I didn't need the leading "/". Well, I'll use it from
now =)
> I would probably use the setIcon(Image) version, and define a default Image
> instance by calling Image.load(). But either way will work.
>
I tried use the version you suggested, but I got an error
(MalformedURLException).
Where am I missing something? See:
...
private String defaultImage = "/img/default.gif";
private Image defaultImg;
...
defaultImg = Image.load(new URL(defaultImage));
...
buttons[aux].setButtonData(new MemGameButtonData(defaultImg,
images36[aux]));
...
public class MemGameButtonData extends ButtonData{
private Image defaultImage;
private Image buttonImage;
public MemGameButtonData(Image defaultImage, Image buttonImage){
super();
this.buttonImage = buttonImage;
this.defaultImage = defaultImage;
setDefaultURL();
}
public void setDefaultURL(){
this.setIcon(defaultImage);
}
public void setButtonURL(){
this.setIcon(buttonImage);
}
public Image getButtonURL(){
return this.getIcon();
}
}
Luiz Gustavo
>
> On Dec 8, 2010, at 8:41 PM, Luiz Gustavo wrote:
>
> Hi Greg,
>
> I use the image in the memory game that I've sended to you.
> I created a specialized ButtonData that receives two Strings in its
> constructor. One of then is de default image, that apears when the button is
> "closed" and the another is the image that apears when the user clicks the
> button.
> I have to do it programmatically 'cause I have to randomize the image
> locations.
>
> I knew about the "@" symbol in the bxml file... but I just had the error
> mentioned... in the source using Pivot 1.5.2 I didn't have to use the
> leading "/" in the path:
>
>
> ...
> private String defaultImage = "/img/default.gif";
> ...
>
> for(int aux = 0; aux < 36; aux++){
> // *images36[aux]* contains the randomized images
> buttons[aux].setButtonData(new MemGameButtonData(*
> defaultImage*, *images36[aux]*));
> buttons[aux].setEnabled(true);
> }
>
> ...
>
>
>
>
> public class MemGameButtonData extends ButtonData{
>
> private String defaultURL;
> private String buttonURL;
>
> public MemGameButtonData(String URLPadrao, String URLBotao){
>
> super();
> this.buttonURL = URLBotao;
> this.defaultURL = URLPadrao;
> setDefaultURL();
> }
>
> public void setDefaultURL(){
> this.setIcon(defaultURL);
> }
>
> public void setButtonURL(){
> this.setIcon(buttonURL);
> }
>
> public Image getButtonURL(){
> return this.getIcon();
> }
> }
>
>
> Cheers,
> Luiz Gustavo
>
>
>
>
>
>
> 2010/12/8 Greg Brown <[email protected]>
>
>> The leading slash is now required in BXML. A leading "@" symbol means
>> "relative to the current file", whereas a leading "/" means relative to the
>> class path (i.e. absolute).
>>
>> However, you appear to be loading your images programmatically rather than
>> in markup - what exactly are you doing with the defaultImage value? There
>> may be an easier way to accomplish what you need.
>>
>> G
>>
>>
>> On Dec 8, 2010, at 7:21 PM, Luiz Gustavo wrote:
>>
>> Hi,
>>
>>
>> I had writen an application using Pivot 1.5.2 that used a gif image for a
>> button, and in the Java source I used the path without a "/" in the begining
>> of the path, like this:
>>
>> private String defaultImage = "img/default.gif";
>>
>> Now, rewriting the application in Pivot 2.0 I had to put the "/" in the
>> begining of the path (otherwise I receive a NullPointerException that tells
>> me the IconURL is null):
>>
>> private String defaultImage = "/img/default.gif";
>>
>> Are the images referenced by an absolute path now, and not relative to the
>> bxml script?
>>
>> --
>> Luiz Gustavo S. de Souza
>>
>> http://luizgustavoss.wordpress.com
>> http://luizgustavoss.blogspot.com
>> http://twitter.com/lugustso
>>
>>
>>
>
>
> --
> Luiz Gustavo S. de Souza
>
> http://luizgustavoss.wordpress.com
> http://luizgustavoss.blogspot.com
> http://twitter.com/lugustso
>
>
>