rectangle class discription link http://docs.oracle.com/javase/8/javafx/api/java
ID: 3668206 • Letter: R
Question
rectangle class discription link
http://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Rectangle.html
What to do Create a two by two pattern of rectangles that resize with the window. Different colors in each rectangle Each rectangle width is 1/3 the width of the pane Each rectangle height is 1/3 the height of the pane Border to left and right is 1/6 width of pane Border to top and bottom is 1/6 width of pane Look at the Rectangle class Rectangle class description What properties of a rectangle will have to be adjusted What else needs to be set? Draw a rough picture and work out coordinates and sizes For example, the x value of the upper left rectangle will pane For example, the y value of the upper left rectangle will pane be 1/6 of the width of the be 1/6 of the height of the paneExplanation / Answer
import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; import javax.swing.JFrame; import javax.swing.JPanel; public class ResizeRectangle extends JPanel { private int SIZE = 8; private Rectangle2D[] points = { new Rectangle2D.Double(50, 50,SIZE, SIZE), new Rectangle2D.Double(150, 100,SIZE, SIZE) }; Rectangle2D s = new Rectangle2D.Double(); ShapeResizeHandler ada = new ShapeResizeHandler(); public ResizeRectangle() { addMouseListener(ada); addMouseMotionListener(ada); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; for (int i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.