Tuesday, June 30, 2015


Puddles with javafx


 programmingpraxis published once in 2013 a riddle for quantity of water than remain after the rain:


here an implementation with javafx. the solution is made with groovy witch make it really easier to understand.




as usual you can find the source code at github :

https://github.com/mooninvader/puddlesfx 



 

Monday, June 22, 2015

IMAGE CROPPER IN JAVAFX


this time this a demonstration of an application that create small pieces from a bigger image and save them on disk in jpeg format :


the transparent rectangle is simply a text field :


     public TextField createRectangle(double x, double y, double width, double height) {
        TextField rec = new TextField();
        rec.setPrefHeight(1);
        rec.setPrefWidth(1);
        container.getChildren().add(rec);
        rec.setOpacity(0.7f);
        rec.setAlignment(Pos.BOTTOM_CENTER);
        rec.setTranslateX(x);
        rec.setTranslateY(y);
        rec.setFont(Font.font("System", FontWeight.BOLD, 14));
        rec.setPromptText("give a file name");
        rec.setCursor(Cursor.OPEN_HAND);      
        currentRect = rec;

        rec.addEventHandler(MouseEvent.MOUSE_PRESSED, (MouseEvent e) -> {
            if (currentMode == Mode.SELECT) {
                markRectangleAsCurrent((TextField) e.getSource());
                dragAnchor = new Point2D(e.getSceneX(), e.getSceneY());
                initX = ((TextField) e.getSource()).getTranslateX();
                initY = ((TextField) e.getSource()).getTranslateY();
            }
        });

        rec.addEventHandler(MouseEvent.MOUSE_DRAGGED, (MouseEvent e) -> {
            ((TextField) e.getSource()).setTranslateX(initX + e.getSceneX() - dragAnchor.getX());
            ((TextField) e.getSource()).setTranslateY(initY + e.getSceneY() - dragAnchor.getY());
            surroundRectangleWithCorners(((TextField) e.getSource()));
        });

        rec.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {            
            this.currentMode=Mode.SELECT;
        });

        rec.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
            this.currentMode=Mode.CREATE;
        });

        rec.addEventHandler(KeyEvent.KEY_PRESSED, (KeyEvent e) -> {

            if (e.getCode() == KeyCode.DELETE && currentRect == ((TextField) e.getSource())) {
                container.getChildren().remove(currentRect);
                setCurrentRectangleToNull();
            }           
        });
        return rec;
    }
and the red dot are instance of Rectangle:



the code can be found on github :

https://github.com/mooninvader/imageCropperFx 

Tuesday, June 16, 2015

MINESWEEPER WITH JAVAFX

A simple minesweeper game made with netbeans 8 and javafx.





you can find the code at github. here the link :