|
From: Mark R. D. <mdi...@la...> - 2003-08-13 20:16:53
|
Forget the first part of this message [the second still stands ;-)], I
had a brain freeze. I'll add the addListener code to the method. I
suspect these should be called "createButton" since they are doing that
and not "add"ing a previously created button.
-M.
Mark R. Diggory wrote:
> In general I see two different policies going on in Controller when it
> comes to buttons The first one adds the listener to the button in its
> method, the second doesn't. I wonder if adding a listener twice
> generates two events to that listener? If not then it would be wise to
> set the listener in all Button methods.
>
> /**
> * Adds a user defined button to the toolbar. This must be called
> * in the model's setup method or the button will not be added.
> *
> * @param label the label for the new JButton
> * @param listener the ActionListener fired when the button is clicked
> */
>
> public JButton addButton(String label, ActionListener listener) {
> JButton b = new JButton(label);
> int width = b.getPreferredSize().width - 10;
> b.setMinimumSize(new Dimension(width, 31));
> b.setMaximumSize(b.getMinimumSize());
> b.setPreferredSize(b.getMinimumSize());
> b.addActionListener(listener);
>
> userButtons.add(b);
> return b;
> }
>
> /**
> * Adds a user defined button to the toolbar. This must be called
> * in the model's setup method or the button will not be added.
> *
> * @param b the JButton to add
> */
> public JButton addButton(JButton b) {
> userButtons.add(b);
> return b;
> }
>
>
> This silly thing is that the behaviors in these methods can easily be
> attained view code, why create all these methods to support something
> Swing already does naturally.
>
> JButton b = new JButton(new ImageIcon(path));
> b.addActionListener(listener);
> controller.addButton(b);
>
> JButton b = new JButton("Foobar");
> b.addActionListener(listener);
> controller.addButton(b);
>
> JButton b = new JButton("Foobar", new ImageIcon(path));
> b.addActionListener(listener);
> controller.addButton(b);
>
> I wonder if its good to create many different methods to support button
> making in the controller when it can be done so easily (and with
> ultimate flexibility) externally?
>
> -Mark
>
>
> Vos, Jerry R. wrote:
>
>> In Controller.addIconButton(String path, ActionListener l)
>>
>> The actionlistener is never added to the created button.
>>
>>
>>
>> Original:
>>
>> *public* JButton addIconButton(String path, ActionListener l) {
>>
>> JButton b = *new* JButton(*new* ImageIcon(path));
>>
>> userButtons.add(b);
>>
>> *return* b;
>>
>> }
>>
>>
>>
>> fixed:
>>
>> *public* JButton addIconButton(String path, ActionListener l) {
>>
>> JButton b = *new* JButton(*new* ImageIcon(path));
>>
>> *b.addActionListener(l);*
>>
>> userButtons.add(b);
>>
>> *return* b;
>>
>> }
>>
>>
>>
>> Jerry Vos
>>
>> ANL
>>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Repast-developer mailing list
> Rep...@li...
> https://lists.sourceforge.net/lists/listinfo/repast-developer
|