view src/alice/test/topology/aquarium/fx/Aquarium.java @ 15:3458bde834d3

remove NullPointerException
author e095732
date Sat, 02 Feb 2013 02:24:05 +0900
parents bf24d5200770
children 5e6d40908c60
line wrap: on
line source

package alice.test.topology.aquarium.fx;

import java.io.IOException;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class Aquarium extends Application {

	private ObservableList<Node> list;
	public AnchorPane root;
	
	@Override
	public void start(Stage primaryStage) throws IOException {
		if (getClass().getResource("aquarium.fxml") != null){
			root = FXMLLoader.load(getClass().getResource("aquarium.fxml"));
		} else if (getClass().getClassLoader().getResource("aquarium.fxml") != null){
			root = FXMLLoader.load(getClass().getClassLoader().getResource("aquarium.fxml"));
		} else {
			System.out.println("error");
			System.exit(0);
		}
		// AquariumController cont = (AquariumController) loader.getController(); get Controller instance
		ImageView iv = (ImageView) root.getChildren().get(1);
		Image img = new Image("fish.jpg");
		iv.setImage(img);
		list = root.getChildren();
		new Share("image1");
		new SetTranslation(iv, "image1");
		Scene scene = new Scene(root);
        
        primaryStage.setScene(scene);
        primaryStage.setResizable(false);
        primaryStage.show();
        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
        	public void handle(WindowEvent we) {
            	System.exit(0);
            }
        });
        
        new AddObject(this);
	}

	public static void main(String[] args) {
		launch(args);
	}
	
	public void run(){
		launch();
		
	}
	
	public ObservableList<Node> getList(){
		return list;
	}
}