Institute of Computer Science
Courses.cs.ut.ee Institute of Computer Science University of Tartu
  1. Courses
  2. 2018/19 spring
  3. Object-Oriented Programming (Narva College) (LTAT.NR.003)
ET
Log in
Attention! Courses webpage might experience technical difficulties on 19.05.2026 between 18.00 and 18.30. Please don't submit any homeworks and modify any pages during this time. Sorry for the inconvenience.

Object-Oriented Programming (Narva College) 2018/19 spring

  • Home
  • Materials
  • Java Glossary
  • Source Example
  • Cheat sheet (S1-S6)
  • Grading
  • Links
Session 7

Canvas

Coming back to the painting, artists have been painting their masterpieces on the canvas. A canvas is also available in JavaFX - Canvas class.

Here is our black square, but with a canvas:

    public void start(Stage primaryStage) {
        Group root = new Group(); // create a root node
        Canvas canvas = new Canvas(535, 535); // create a canvas
        GraphicsContext gc = canvas.getGraphicsContext2D(); // graphics content
        gc.fillRect(50, 50, 435, 435); // square
        root.getChildren().add(canvas);  // place a canvas on the scene
        Scene scene1 = new Scene(root, 535, 535, Color.SNOW);  // create a scene
        primaryStage.setTitle("Black square");  // set the stage title
        primaryStage.setScene(scene1);  // place the scene on the stage
        primaryStage.show();  // display the stage
    }

Useful link: more examples of working with the canvas can be found here.

Session 7
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment