From 418535c89c31138866c4e35fde8cf6bd14787211 Mon Sep 17 00:00:00 2001 From: Zocker1999NET Date: Sun, 10 Jul 2016 20:57:49 +0200 Subject: [PATCH] Test Implementierung mit JavaFX --- Actor.java | 23 ++++++++++++++++++++++- Greenfoot.java | 26 ++++++++++++++++++++++---- GreenfootImage.java | 6 +----- World.java | 21 +++++++++++++++++++-- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Actor.java b/Actor.java index c991251..03e8b23 100644 --- a/Actor.java +++ b/Actor.java @@ -1,5 +1,26 @@ - +package greenfootReplacement; + +import javafx.scene.image.ImageView; public class Actor { + + GreenfootImage image = null; + + private static javafx.scene.image.Image getFXImage() throws java.io.IOException { + java.awt.image.BufferedImage i = image.getAwtImage(); + if (!(image instanceof java.awt.image.RenderedImage)) { + java.awt.image.BufferedImage bufferedImage = new java.awt.image.BufferedImage(image.getWidth(null), image.getHeight(null), java.awt.image.BufferedImage.TYPE_INT_ARGB); + java.awt.Graphics g = bufferedImage.createGraphics(); + g.drawImage(image, 0, 0, null); + g.dispose(); + image = bufferedImage; + } + java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); + javax.imageio.ImageIO.write((java.awt.image.RenderedImage) image, "png", out); + out.flush(); + java.io.ByteArrayInputStream in = new java.io.ByteArrayInputStream(out.toByteArray()); + return new javafx.scene.image.Image(in); + } + } \ No newline at end of file diff --git a/Greenfoot.java b/Greenfoot.java index 594e5c4..b3b26bb 100644 --- a/Greenfoot.java +++ b/Greenfoot.java @@ -1,18 +1,36 @@ - +package greenfootReplacement; + +import javafx.application.Application; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; /** Ersetzt die Greenfoot Klasse von Greenfoot und hält das Programm am Laufen. */ -public class Greenfoot { +public class Greenfoot extends Application { + + private Stage mainStage = null; - private static World currentWorld = null; + private World currentWorld = null; public static void main(String[] args) { + launch(args); + } + + @Override public void start(Stage primaryStage) throws Exception { + mainStage = primaryStage; + mainStage.setTitle("Zweiundvierzig - Greenfoot as JavaFX"); setWorld(new Start_Load()); + mainStage.show(); } public static void setWorld(World w) { - + currentWorld = w; + mainStage.setScene(currentWorld); } } \ No newline at end of file diff --git a/GreenfootImage.java b/GreenfootImage.java index fd4749b..e87cf50 100644 --- a/GreenfootImage.java +++ b/GreenfootImage.java @@ -1,4 +1,4 @@ - +package greenfootReplacement; import java.awt.Color; import java.awt.image.BufferedImage; @@ -28,10 +28,6 @@ public class GreenfootImage { } - public GreenfootImage(String txt, int size, Color foreCol, Color backCol, Color outline) { - - } - public BufferedImage getAwtImage() { return image; } diff --git a/World.java b/World.java index 4d2fc34..cdf136f 100644 --- a/World.java +++ b/World.java @@ -1,5 +1,22 @@ - +package greenfootReplacement; -public class World { +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; + +public abstract class World extends Scene { + + AnchorPane layout = null; + + public World(int width, int height, int cellSize) { + super(new AnchorPane(), width * cellSize, height * cellSize); + + } + + public void act(); + + } \ No newline at end of file