-
Notifications
You must be signed in to change notification settings - Fork 57
/
Example2.java
47 lines (39 loc) · 1.32 KB
/
Example2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.FontPosture;
import javafx.scene.image.Image;
public class Example2 extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage theStage)
{
theStage.setTitle( "Canvas Example" );
Group root = new Group();
Scene theScene = new Scene( root );
theStage.setScene( theScene );
Canvas canvas = new Canvas( 400, 200 );
root.getChildren().add( canvas );
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFill( Color.RED );
gc.setStroke( Color.BLACK );
gc.setLineWidth(2);
Font theFont = Font.font( "Times New Roman", FontWeight.BOLD, 48 );
gc.setFont( theFont );
gc.fillText( "Hello, World!", 60, 50 );
gc.strokeText( "Hello, World!", 60, 50 );
Image earth = new Image( "earth.png" );
gc.drawImage( earth, 180, 100 );
theStage.show();
}
}