This Example, Six Lines, will produce the same output as Java Example 2, except now it is written in Jython.
# ex02.py
# Six Lines
from javafx.application import Application
from javafx.scene import Scene
from javafx.scene import Group
from javafx.scene.paint import Color
from javafx.scene.shape import Line
from javafx.scene.shape import StrokeLineCap
class Ex02(Application):
def start(self, stage):
stage.setTitle("Example 2. Six Lines")
root = Group()
# Red line - top and bottom
redTop = Line(10, 10, 630, 10)
redTop.setStroke(Color.RED)
redTop.setStrokeWidth(10)
redBot = Line(10, 470, 630, 470)
redBot.setStroke(Color.RED)
redBot.setStrokeWidth(10)
root.getChildren().addAll(redTop,redBot)
# Green Line -left and right
greenLeft = Line(10, 30, 10, 450)
greenLeft.setStroke(Color.GREEN)
greenLeft.setStrokeWidth(10)
greenLeft.setStrokeLineCap(StrokeLineCap.ROUND)
greenRight = Line(630, 30, 630, 450)
greenRight.setStroke(Color.GREEN)
greenRight.setStrokeWidth(10)
greenRight.setStrokeLineCap(StrokeLineCap.ROUND)
root.getChildren().addAll(greenLeft,greenRight)
# Yellow lines - diagonal lines
yellow1 = Line(30, 30, 610, 450)
yellow1.setStroke(Color.YELLOW)
yellow1.setStrokeWidth(10)
yellow1.getStrokeDashArray().addAll(20.0, 10.0, 20.0)
yellow2 = Line(30, 450, 610, 30)
yellow2.setStroke(Color.YELLOW)
yellow2.setStrokeWidth(10)
yellow2.getStrokeDashArray().addAll(20.0, 10.0, 20.0)
root.getChildren().addAll(yellow1,yellow2)
scene = Scene(root, 640, 480, Color.CYAN)
stage.setScene(scene)
stage.show()
if __name__ == '__main__':
Application.launch(Ex02().class, [])