Write a program that draws exactly look like the below figur
Write a program that draws exactly look like the below figure onto a DrawingPanel.The Overall frame has a white background and is 210 pixels wide and 210 pixels hight. Each of the nine stamp is 50 x 50 pixels in size. Notice that the boardlines of each stamp are black colored
Love Java Java LJSolution
first let us draw the rectangle main frame divided into 9 equal halves
-------
public class RectanglesDrawing extends JFrame {
public RectanglesDrawing() {
super(\"Rectangles Drawing\");
getContentPane().setBackground(Color.WHITE);
setSize(480, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
void drawRectangles(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
// code to draw rectangles goes here...
g2d.draw(new Rectangle(45,45 , 900, 900)); //main rectangle border
/* notice the co-ordinates and the height and width of our rectangle, we will divide this so that we can get 9 equal halves*/
//rectangles for the 9 halves
g2d.draw(new Rectangle(15,15 , 100, 100));
g2d.draw(new Rectangle(45,15 , 100, 100));
g2d.draw(new Rectangle(75 ,15, 100, 100));
g2d.draw(new Rectangle(15,45 , 100, 100));
g2d.draw(new Rectangle(45,45 , 100, 100));
g2d.draw(new Rectangle(75,45 , 100, 100));
g2d.draw(new Rectangle(15,75 , 900, 900));
g2d.draw(new Rectangle(45,75 , 900, 900));
g2d.draw(new Rectangle(75,75 , 900, 900));
}
public void paint(Graphics g) {
super.paint(g);
drawRectangles(g);
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new RectanglesDrawingExample().setVisible(true);
}
});
}
}
--------------------
now we will draw some of the designs given in the figure:
----------------
the code for the two ovals filled with circles
**this piece of code will go after the g2d.draw(new Rectangle(45,45 , 900, 900)); lines in the above code**
g.drawOval(x, y, 50, 75); //keep x and y depending on the rect half coordinate
g.drawOval(x, y, 50, 75); //keep x and y depending on the rect half coordinate
//for circle keep length and width same
g.setColor(Color.RED);
//keep x and y depending on your oval
-------------------------------
we will now do the love java part
-----------------
-----------------------------
now we will do the rectangular pattern
-------------
-----------------
brute forcely draw each rectanlges with the appropriate co-ordinated acc to the image
--------------------
thank you

