documentation for Swing - Java data

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

documentation for Swing - Java data

Claude Marinier
Good afternoon,

Thank you for all your efforts. Kawa has impressed me so far.

I am experimenting with Kawa and Swing. I need to provide choices to
a JComboBox and have not found documentation on how to pass data to
Java/Swing.

Where can I find this?

Thank you.

--
Claude Marinier
Reply | Threaded
Open this post in threaded view
|

Re: documentation for Swing - Java data

Sudarshan S Chawathe
> From: Claude Marinier <[hidden email]>
> Date: Fri, 16 Dec 2016 16:15:22 -0500
 
> I am experimenting with Kawa and Swing. I need to provide choices to
> a JComboBox and have not found documentation on how to pass data to
> Java/Swing.
>
> Where can I find this?

I'm not sure if I understand the question fully, but in general it is
easy to call Java constructors and methods from Kawa, and similarly to
pass Scheme data to Java via implicit or explicit conversion.  The
chapter titled "Object, Classes and Modules" in the Kawa manual has many
useful details in this regard.  (The "lambda as shorthand for an
anonymous class"/SAM-conversion is one of my favorite features,
especially when using Swing.)

A bit more specific to your question perhaps, the code fragment in the
JComboBox tutorial at

  https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html

i.e.:

  String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };

  //Create the combo box, select item at index 4.
  //Indices start at 0, so 4 specifies the pig.
  JComboBox petList = new JComboBox(petStrings);
  petList.setSelectedIndex(4);
  petList.addActionListener(this);

may be written in Kawa along the following lines:

  (let* ((pet-strings (String[] "Bird" "Cat" "Dog" "Rabbit" "Pig"))
         (pet-list (javax.swing.JComboBox pet-strings)))
    (pet-list:setSelectedIndex 4)
    (pet-list:addActionListener (this)))
       
assuming it occurs in the the scope of a define-simple-class or
equivalent so that the (this) makes sense.

Regards,

-chaw

 
   
Reply | Threaded
Open this post in threaded view
|

Re: documentation for Swing - Java data

Claude Marinier
AllĂ´,

That is a very useful hint. I was able to use this pattern for the
JComboBox and other things.

Thank you.

--
Claude Marinier


On 16 December 2016 at 16:46, Sudarshan S Chawathe <[hidden email]> wrote:

>> From: Claude Marinier <[hidden email]>
>> Date: Fri, 16 Dec 2016 16:15:22 -0500
>
>> I am experimenting with Kawa and Swing. I need to provide choices to
>> a JComboBox and have not found documentation on how to pass data to
>> Java/Swing.
>>
>> Where can I find this?
>
> I'm not sure if I understand the question fully, but in general it is
> easy to call Java constructors and methods from Kawa, and similarly to
> pass Scheme data to Java via implicit or explicit conversion.  The
> chapter titled "Object, Classes and Modules" in the Kawa manual has many
> useful details in this regard.  (The "lambda as shorthand for an
> anonymous class"/SAM-conversion is one of my favorite features,
> especially when using Swing.)
>
> A bit more specific to your question perhaps, the code fragment in the
> JComboBox tutorial at
>
>   https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html
>
> i.e.:
>
>   String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };
>
>   //Create the combo box, select item at index 4.
>   //Indices start at 0, so 4 specifies the pig.
>   JComboBox petList = new JComboBox(petStrings);
>   petList.setSelectedIndex(4);
>   petList.addActionListener(this);
>
> may be written in Kawa along the following lines:
>
>   (let* ((pet-strings (String[] "Bird" "Cat" "Dog" "Rabbit" "Pig"))
>          (pet-list (javax.swing.JComboBox pet-strings)))
>     (pet-list:setSelectedIndex 4)
>     (pet-list:addActionListener (this)))
>
> assuming it occurs in the the scope of a define-simple-class or
> equivalent so that the (this) makes sense.
>
> Regards,
>
> -chaw
>
>
>



--
Claude Marinier
Reply | Threaded
Open this post in threaded view
|

Re: documentation for Swing - Java data

Per Bothner


On 12/21/2016 03:30 AM, Claude Marinier wrote:
> That is a very useful hint. I was able to use this pattern for the
> JComboBox and other things.


Also check out this link for the more compact keyword-based syntax.
It has a number of Swing examples;

https://www.gnu.org/software/kawa/Allocating-objects.html
--
        --Per Bothner
[hidden email]   http://per.bothner.com/