//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** @author Casey Bowman * @version 1.1 * @date Mon Mar 09 14:35:42 EDT 2015 * @see (License) MIT style license */ import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; import javafx.scene.layout.Pane; //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** A simple javafx application to display a rectangle in a window. * @const screenWidth the width of the window * @const screenHeight the height of the window * @const rectWidth the width of the rectangle * @const rectHeight the height of the rectangle * @const rectX the x-coordinate of the top left corner of the rectangle * @const rectY the y-coordinate of the top left corner of the rectangle * @const root the group to which the scene belongs * @const scene the scene for this window * @const pane a pane to hold the rectangle */ public class FXRectangle extends Application { private int screenWidth = 600; private int screenHeight = 600; private int rectWidth = 50; private int rectHeight = 50; private int rectX = 100; private int rectY = 100; Group root = new Group (); Scene scene = new Scene (root, screenWidth, screenHeight, Color.web ("#33CC99")); // the scene needs a group, width, height, and color Pane pane = new Pane (); //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Main method. Calls internal method launch (String[]) * of Application class. */ public static void main (String[] args) { launch (args); } // main //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** start method. Called by launch. Directs the creation of * components and windows for the fx application. * @param stage the stage for this application */ @Override public void start (Stage stage) { Rectangle r = makeRect (rectX, rectY, rectWidth, rectHeight); setRect (r); addRect (r); addPane (); showWindow (stage); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** this method creates a Rectangle of the appropriate size. * @param x the x-coordinate for the top left corner of the rectangle * @param y the y-coordinate for the top left corner of the rectangle * @param w the width of the rectangle * @param h the height of the rectangle */ public Rectangle makeRect (int x, int y, int w, int h) { return new Rectangle (x, y, w, h); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** this method sets some stylistic parameters of the rectangle. I've * chosen to set the arc width and height which rounds the corners, * I've set the stroke color and width which styles the border, * and I've set the fill which colors the interior of the rectangle. * @param r the rectangle to style */ public void setRect (Rectangle r) { r.setArcWidth (10); r.setArcHeight (10); r.setStroke (Color.BLACK); r.setStrokeWidth (3); r.setFill (Color.web ("#EE3344")); } // setRect //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** this method adds a rectangle to the pane. * @param r the rectangle to add. */ public void addRect (Rectangle r) { pane.getChildren (). add (r); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** this method adds the pane to the group. */ public void addPane () { root.getChildren (). add (pane); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** this method displays the window. * @param stage the stage to display. */ public void showWindow (Stage stage) { stage.setScene (scene); stage.show (); } // showWindow } // FXRectangle