Hello, I am vegaseat, the goofy moderator from the Python forum of DaniWeb. I wanted to know if anyone in the Java forum has played around with Java based Python, also known as Jython.

Jython uses easy to learn Python syntax and can use the Java libraries. To make a short story long, here is an example ...

""" jy_List_99BoB2.py
create the full lyrics of the '99 bottle of beer' song
and show in a Jython (Java based Python) scrollable list box

Download file jython_installer-2.5.2.jar 
from http://www.jython.org/downloads.html

On Windows just double click the .jar file
and Java will install the Jython program
into a directory called jython2.5.2

to this .py file on Windows use:  
Jython.bat jy_List_99BoB2.py

tested with jython2.5.2  by  vegaseat
"""

# import needed Java libraries
# swing is the Java GUI toolkit
from javax.swing import *
from java.awt import Color

# creates all lines of '99 bottles of beer' lyrics
# using some sensible slicing
list_99bob = []
bottle = " %s bottle"
beer = "s of beer on the wall!"
take = "! Take one down, pass it around,"
for k in range(99, 0, -1):
    s1 = ((bottle % k + beer[k==1:])*2)[:-13]
    s2 = bottle % (k-1 or "No")
    s3 = beer[k==2:-1] + "!"
    #print(s1 + take + s2 + s3  # test)
    list_99bob.append(s1 + take + s2 + s3)

frame = JFrame('99 Bottles of Beer song')
# allows frame corner x to exit properly
frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
frame.setLocation(100, 150)
frame.size = (400, 300)

# create a list box and load it with the lyrics
swing_list = JList(list_99bob)
# give it a little color
swing_list.background = Color.yellow
# make it scrollable
swing_list_scroll = JScrollPane(swing_list)

frame.add(swing_list_scroll)
frame.visible = True

If you have any Jython code samples, you are invited to the Python forum for an informal posting.

Oh, I almost forgot, Python and therefore Jython are OOP languages and you can write your code in OOP style of course. For simple stuff I usually don't.

peter_budo commented: Nice sample vegaseat ;) +16

Jython, now that's a name I've not heard mention in many years...

I'm assuming that the aim here is to make Java developers aware of the JVM port of Python programming language and the goodies which it brings with it. However, those thinking of making a transition from CPython to Jython in hope of a better GC and threading, please make sure you read the "differences between CPython and Jython" page (not sure how updated that page is, but worth a read).

As a side note, "Grinder", the load testing framework uses Jython as its scripting language. :-)

I'm assuming that the aim here is to make Java developers aware of the JVM port of Python programming language and the goodies which it brings with it. However, those thinking of making a transition from CPython to Jython in hope of a better GC and threading, please make sure you read the "differences between CPython and Jython" page (not sure how updated that page is, but worth a read).

As a side note, "Grinder", the load testing framework uses Jython as its scripting language. :-)

Looks like that article is from 2007 or earlier, a little outdated as Jython has made many improvements. Using Jython as a scripting language for Java programs is however not a bad idea.

Please read original post before posting to avoid embarrassed entries like this. Question was about Jython not about Java GUI components and designs

Actually, to get to know Jython you have to know Python and Java. I know nothing about Java (at first look it is C+- to me), so the tutorial was helpful for me. I am personally looking more at GUI programming with Jython, swing is such a gem!

Actually, to get to know Jython you have to know Python and Java. I know nothing about Java (at first look it is C+- to me), so the tutorial was helpful for me. I am personally looking more at GUI programming with Jython, swing is such a gem!

Yes these tutorials are helpful if you looking to learn about Swing. Nevertheless it hasn't got direct relevance to your original post, therefore reply is off topic.

Sorry!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.