Re: Basic 2d graphics in Java
On 12/12/2013 11:45 AM, tomcees_pc@yahoo.com wrote:
Hello:
I'm working through re-learning java and would like to solicit some help.
Can anyone share some simple java code to:
1. Set up a small (say 320w x 240h) 2d window.
2. Set(color) and Read (color) of pixels within this window.
TIA for your help,
TomC
Just cause so many are heaping on Swing lately.
package pixel.test;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class PixelTest extends Application {
WritableImage image = new WritableImage(320,240);
PixelReader pixelReader = image.getPixelReader();
PixelWriter pixelWriter = image.getPixelWriter();
//setPixel and readPixel left as an exercise
@Override
public void start(Stage primaryStage) {
ImageView imageView = new ImageView();
imageView.setImage(image);
StackPane root = new StackPane();
root.getChildren().add(imageView);
Scene scene = new Scene(root, 320, 240);
primaryStage.setTitle("Pixel Test");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}