GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Showing posts with label Jython. Show all posts
Showing posts with label Jython. Show all posts

Thursday, December 23, 2010

Looping In Jython

>>> for i in range(3):
...     print i
0
1
2
Share/Bookmark

Method In Jython

Here's a code that much like Python:
>>> def getLol():
...     print "Hello, Lol"
...
>>> getLol()
Hello, Lol
Share/Bookmark

Class In Jython

Here's a code on how to define a class in Jython:

>>> class Hello:
...    def __init__(self,name="no name"):
...        self.name = name
...    def greeting(self):
...        print "Hello, ",self.name
...
>>> luna = Hello("Luna Maya")
>>> luna.greeting()
Hello, Luna Maya
Share/Bookmark

Wednesday, December 22, 2010

Reading Text Files In Jython

>>> file = open("data.txt","r");
>>> for line in file.readlines():
...    print line
...
Holla the world
This come from text file
>>> file.close()
    
Share/Bookmark

Swing Application From Jython

>>> from javax.swing import *
>>> def hello():
...     frame = JFrame("Holla, Jython")
...     frame.setSize(400,300)
...     frame.setLocation(200,100)
...     frame.show()
... 
>>> hello()
             

Share/Bookmark

First Script In Jython

To get Jython, please download it from Jython web site. After you download, you need to install it by command:
C:\java -jar jython_installer.2.2.1.jar
After the installation completes, please move to jython\bin directory and run jython.bat
C:\jython\bin\jython.bat

>>> print "Hello, Jython"
Hello, Jython

>>> from java.util import Vector
>>> v = Vector()
>>> dir(v)
>>> v.add('larry page')
>>> v.add('barack obama')
>>> v.add('bill gates')
>>> for value in v:
>>>     print v
larry page
barack obama
Publish Post

bill gates
         
Share/Bookmark