Difference between Java Approach and Python Approach

Asked by Prateek Sahu

I am using Eclipse for Sikuli scripting...

I am succefully able to run my scripts...

I have configured pydev and Created Python project and using jython interpreter for running scripts

Now I want to know is it possible to use java features...If yes how...

How is it different from JAVA project???

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

When running a Sikuli script (Python language) in Jython interpreter (or with the means of Sikuli IDE), you can import and use all Java classes, found in the class path.

--- differences to plain Java code

- no variable declarations needed
- no trailing ; needed
- creating an instance just by saying
someObject = SomeJavaClass()
creates a new instance of java class SomeJavaClass

So just import the needed class and start coding according to the documented Java API.

example:

--- taking a screenshot and write it to an image file
from java.awt import *
from java.io import File
from javax.imageio import ImageIO

robot = Robot()

theImage = robot.createScreenCapture(Rectangle(Toolkit.getDefaultToolkit().getScreenSize()))
ImageIO.write(theImage, "png", File(r"C:\myPic.png"))

Revision history for this message
Prateek Sahu (prateek-sahu01apr) said :
#2

Thanks RaiMan, that solved my question.