I started this but need to convert it using JavaFX
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ArtProject {
public static void main(String[] args) throws IOException {
/*this will be the size of the rectangle background with
circles inside the image*/
int width = 400;
int height = 250;
int circleWidth = height;
//create an image object
BufferedImage bufferedImage = new BufferedImage(width,
height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferedImage.createGraphics();
//this sets the background color to white
g2d.setColor(Color.white);
g2d.fillRect(0, 0, width, height);
//this will be the colors of three different circles
g2d.setColor(Color.pink);
g2d.fillOval(150, 0, circleWidth, height);
g2d.setColor(Color.darkGray);
g2d.fillOval(75, 0, circleWidth, height);
g2d.setColor(Color.gray);
g2d.fillOval(0, 0, circleWidth, height);
/*this will set the color, font and size of the text and place it
at the
lower right corner*/
Font stringFont = new Font("Century Gothic", Font.PLAIN, 16);
g2d.setFont(stringFont);
g2d.setColor(Color.black);
g2d.drawString("text here", 275, 240);
g2d.dispose();
//this will create the file the image will be saved to.
File file = new File("javaimage.jpg");
ImageIO.write(bufferedImage, "jpg", file);
}
}
Answer:
Here is the code and related screenshots. All you need to do is extend the class called Application for Javafx. Next, you got to use canvas to create the images that's all. Please drop me a comment if you have any doubts, I'll be glad to help you. Make sure you go through the comments for better understanding fo the code.
O/P Screenshot:
Code
import javafx.application.Application; import javafx.embed.swing.SwingFXUtils; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.image.WritableImage; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; import javax.imageio.ImageIO; import java.awt.image.RenderedImage; import java.io.File; import java.io.IOException; public class ArtProject extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) throws IOException { /*this will be the size of the rectangle background with circles inside the image*/ int width = 400, height = 250, circleWidth = height; // Create the Canvas, set height & width Canvas canvas = new Canvas(width, height); canvas.setWidth(width); canvas.setHeight(height); // Here is the graphics for canvas GraphicsContext gc = canvas.getGraphicsContext2D(); // All your specifications gc.setFill(Color.WHITE); gc.fillRect(0, 0, width,height); //this will be the colors of three different circles gc.setFill(Color.PINK); gc.fillOval(150, 0, circleWidth, height); gc.setFill(Color.DARKGREY); gc.fillOval(75, 0, circleWidth, height); gc.setFill(Color.GRAY); gc.fillOval(0, 0, circleWidth, height); // font Font font = Font.font("Century Gothic", FontWeight.NORMAL, 25); gc.setFont(font); gc.setFill(Color.BLACK); gc.strokeText("text here", 275, 240); // Create the Pane Pane root = new Pane(); // Set the Style-properties of the Pane root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;" + "-fx-border-width: 2;" + "-fx-border-insets: 5;" + "-fx-border-radius: 5;" + "-fx-border-color: blue;"); // Add the Canvas to the Pane root.getChildren().add(canvas); // Create the Scene, add it to the stage Scene scene = new Scene(root); stage.setScene(scene); stage.setTitle("Creation of a Circles"); // writing it to a file WritableImage writableImage = new WritableImage(width, height); canvas.snapshot(null, writableImage); RenderedImage renderedImage = SwingFXUtils.fromFXImage(writableImage, null); File file = new File("javaimage.jpg"); ImageIO.write(renderedImage, "jpg", file); // Simply display the canvas stage.show(); } }
Code screenshots
I started this but need to convert it using JavaFX import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage;...
Assignment Λ You shall write a Java program that accepts 5 command-line arguments and generates an image of a Sierpinski triangle, as a 24- bit RGB PNG image file. Specifications The command-line arguments shall consist of the following 1. The width (in pixels) of the image, as a positive decimal integer 2. The height (in pixels) of the image, as a positive decimal integer 3. The minimum area (in pixels) that a triangle must have in order to be drawn,...
Hi. I require your wonderful help with figuring out this challenging code. import java.awt.Color; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; public class ImageLab { /* * This is the grayscale example. Use it for inspiration / help, but you dont * need to change it. * * Creates and returns a new BufferedImage of the same size as the input * image. The new image is the grayscale version of the input (red, green, and * blue components averaged together)....
import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; public class RedGamePiece extends GamePiece { public RedGamePiece (int row, int col) { super (row, col, Player.RED); } public RedGamePiece (Position pos) { this (pos.r, pos.c); } protected boolean validNonJump (int dr, int dc, GameSquares squares) { if ((dr == -1) && ( (dc == -1) || (dc == 1) )) { if (squares.getSquare(pos.r + dr, pos.c + dc).getPiece() == null) return true; } return false; } protected boolean validJump (int dr,...
***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class DrawingPanel implements ActionListener { public static final int DELAY = 50; // delay between repaints in millis private static final String DUMP_IMAGE_PROPERTY_NAME = "drawingpanel.save"; private static String TARGET_IMAGE_FILE_NAME = null; private static final boolean PRETTY = true; // true to anti-alias private static boolean DUMP_IMAGE = true; // true to write DrawingPanel to file private int width, height; // dimensions...
could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...
import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...
import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...
Lab Description: Using graphics, polygons, and arrays, draw the tree shown below. You can change the tree anyway you like to make it your own. Sample Data Sec below Files Needed:: GraphicaRunner.java Tree.java Sample Output: import java.awt.Graphics; import java.awt.color; import java.awt.Polygon; import java.awt.Font; import java.awt.Canvas; public class Tree extends Canvas public Tree() setBackground (Color.WHITE) public void paint ( Graphics window) window. setColor (Color.RED); window.setFont (new Font("TAHOMA" ,Font.BOLD,12) window.drawstring("Lab14h Tree Lab", 50, 50) tree(window); IONaA , Font.BOL.D,12) public void tree(Graphics window)...
Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles. You will need to define a Triangle class containing a single instance variable, representing the length of one of the triangle’s sides. Have the program create circles, rectangles, and triangles with equal probability. Circle and Rectangle is done, please comment on your methods so i can understand */ package NervousShapes; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class...
please help me to creating UML class diagrams. Snake.java package graphichal2; import java.awt.Color; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Random; enum Dir{L, U, R, D}; class Food { public static int FOODSTYLE = 1; private int m = r.nextInt(Yard.WIDTH / Yard.B_WIDTH); private int n = r.nextInt(Yard.HEIGHT / Yard.B_WIDTH - 30/Yard.B_WIDTH) + 30/Yard.B_WIDTH;// 竖格 public static Random r = new Random(); public int getM() { return m; } public void setM(int m)...