-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowsXPsimulator.java
59 lines (50 loc) · 2.1 KB
/
WindowsXPsimulator.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
48
49
50
51
52
53
54
55
56
57
58
59
package windowsxpsimulator;
import java.awt.Toolkit;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class WindowsXPsimulator extends Application {
private final Canvas canvas;
private final GraphicsContext gc;
private final Image desktop, fout;
private final EventHandler<MouseEvent> onMouseMovedEventHandler;
public WindowsXPsimulator() {
canvas = new Canvas(Toolkit.getDefaultToolkit().getScreenSize().getWidth(), Toolkit.getDefaultToolkit().getScreenSize().getHeight());
// parameters of the constructor = resolution of screen
gc = canvas.getGraphicsContext2D();
fout = new Image(getClass().getResourceAsStream("fout.png")); // error dialog
desktop = new Image(getClass().getResourceAsStream("desktop.png")); //desktop background
onMouseMovedEventHandler = (MouseEvent event) -> {
gc.drawImage(fout,event.getX(),event.getY()); // put a new error dialog on position of mouse
};
canvas.setOnMouseClicked((MouseEvent event) -> {
if(event.getButton() == MouseButton.PRIMARY)
canvas.setOnMouseMoved(onMouseMovedEventHandler); // if primary mouse button is clicked, use the onMouseMovedEventHandler
// for mouse movement handling in the canvas
else if(event.getButton() == MouseButton.SECONDARY) {
gc.drawImage(desktop, 0, 0); // else remove the error dialogs, reset the screen
canvas.setOnMouseMoved(null); // and unregister onMouseMovedEventHandler from the canvas
}
});
}
@Override
public void start(Stage primaryStage) {
gc.drawImage(desktop, 0, 0);
Scene scene = new Scene(new StackPane(canvas));
primaryStage.setTitle("Windows XP");
primaryStage.setScene(scene);
primaryStage.setFullScreen(true);
primaryStage.setFullScreenExitHint("");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}