0

I'm trying to draw the rhombus into each grid section of the 3x3 square grid. Both the codes are pasted. I've tried various methods but could not succeed. Any insight on this matter is greatly appreciated. Thank you.

3x3 square grid

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class threebythree extends JPanel {

	int s = 150;
	
	public threebythree(){
		
		setPreferredSize(new Dimension(450, 450));
		setBackground(Color.WHITE);
		
	}

	public void paintComponent(Graphics g){
		super.paintComponent(g);
		Graphics2D g2d=(Graphics2D)g;
		g2d.translate(60, 50);
		
		
		this.setBackground(Color.WHITE);
		
		for(int x=0; x<3; x++ ){
			for(int y=0; y<3; y++){
				g2d.drawRect(x*s, y*s, s, s);
				
			}			
		}		
	}	
}

Rhombus

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

	public class rhombus extends JPanel {

		public rhombus(){
			JPanel jp2 = new JPanel();
			setPreferredSize(new Dimension(450, 450));
			setBackground(Color.WHITE);
			
		}
		
		
		
		public void paintComponent(Graphics g){
			super.paintComponent(g);
			
			
			Graphics2D g2d=(Graphics2D)g;
			int s = 100;
			
			this.setBackground(Color.WHITE);
			g2d.translate(275, 75);
			g2d.rotate(Math.toRadians(45));
			for(int x=0; x<3; x++ ){
				for(int y=0; y<3; y++){
					g2d.drawRect(x*s, y*s, s, s);	
					
				}			
			}		
		}	
	}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by NormR1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.