>>> Let's run Python on Mobile

วันอังคาร, มกราคม 23, 2550

jython08.py

import os
import java.lang
from java.awt import Frame,MenuBar,Menu,MenuItem,TextArea,FileDialog
from java.awt.event import ActionEvent
class jython08(java.awt.Frame):
def __init__(self):
self.size=(208,276)
self.myOutput=java.awt.TextArea("Hello UIQ from Jython!!!")
self.add("Center",self.myOutput)
self.myMenuBar=java.awt.MenuBar()
self.myMenu=java.awt.Menu("Menu")
self.myReadFile=java.awt.MenuItem("Read File",actionPerformed=self.doRead)
self.myMenuExit=java.awt.MenuItem("Exit",actionPerformed=self.doExit)
self.myMenuBar.add(self.myMenu)
self.myMenu.add(self.myReadFile)
self.myMenu.add(self.myMenuExit)
self.setMenuBar(self.myMenuBar)
self.setVisible(1)
def doRead(self,event):
d=java.awt.FileDialog(self,"Select File",java.awt.FileDialog.LOAD)
d.setDirectory("D:\\")
d.setVisible(1)
myFile = open(d.getDirectory()+d.getFile(),'r')
myText = myFile.read()
self.myOutput.setText(myText)
myFile.close()
def doExit(self,event):
java.lang.System.exit(0)
if __name__=="__main__":
myApp=jython08()


Jython on UIQ