I need to figure out how to draw the Jamaica 🇯🇲 flag in Java on visual studio code.
I cannot figure out how to draw the flag. All I know is that I must used this header:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
public class JamaicaComponent extends JComponent {
public void paintComponent(Graphics g)
I have tried this code, but it doesn’t work as expected
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
public class JamaicaComponent extends JComponent
{
public void paintComponent(Graphics g)
{
//jamaica flat
g.setColor(Color.GREEN);
g.fillRect(10, 10, 180, 60);
g.setColor(Color.YELLOW);
g.fillRect(10, 70, 180, 60);
g.setColor(Color.BLACK);
g.fillRect(10, 130, 180, 60);
}
}
What the code renders:
2
Answers
Fill with green. Draw two black triangles. Then two yellow lines of appropriate thickness.
Rectangle-only solution.
Just draw the X and Y axes in yellow, and color the four quadrants of the plane alternatingly in black and green. With appropriate isometric projection, that is:
Certainly a good way to memorize flags.