Hi there.
I am required to produce the greek flag however it requires me to use ratios. Below is the excercise question which I was given.
I've got the starting code:
and along with that I've managed to work out the actual design & colour of the flag. The code is shown below:
Thats about it and thanks for reading my post. Can wait for the replies and helping me out inmaking this greek flag.
I am required to produce the greek flag however it requires me to use ratios. Below is the excercise question which I was given.
Make a class that extends JComponent, to draw the Greek flag, as shown in the Figure below.
- The position and width of the white and blue sections should be approximately as shown in the Figure.
- For this flag, the ratio of width to height is 11:8, so for example 220 pixels by 160. It should be drawn as large as possible, but keeping this ratio, whatever the size of the applet window. Any spare space (at the sides, top or bottom) can be drawn any colour you like.
import javax.swing.JCo mponent;
import java.awt.*;
import java.awt.geom.E llipse2D;
class GreekFlag extends JComponent
{
public void paintComponent( Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
int w = getWidth();
int h = getHeight();
double ratio = (double)w/(double)h;
int flagHeight, flagWidth;
if(ratio>11.0/8.0)
{
}
else
{
}
}
}
import java.awt.*;
import java.awt.geom.E llipse2D;
class GreekFlag extends JComponent
{
public void paintComponent( Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
int w = getWidth();
int h = getHeight();
double ratio = (double)w/(double)h;
int flagHeight, flagWidth;
if(ratio>11.0/8.0)
{
}
else
{
}
}
}
import javax.swing.JCo mponent;
import javax.swing.JFr ame;
public class MyFrameViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
final int FRAME_WIDTH = 300;
final int FRAME_HEIGHT = 400;
frame.setSize(F RAME_WIDTH, FRAME_HEIGHT);
frame.setTitle( "Template Viewer");
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
GreekFlag component = new GreekFlag();
frame.add(compo nent);
frame.setVisibl e(true);
}
}
import javax.swing.JFr ame;
public class MyFrameViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
final int FRAME_WIDTH = 300;
final int FRAME_HEIGHT = 400;
frame.setSize(F RAME_WIDTH, FRAME_HEIGHT);
frame.setTitle( "Template Viewer");
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
GreekFlag component = new GreekFlag();
frame.add(compo nent);
frame.setVisibl e(true);
}
}
static void drawFlag(Graphi cs2D g)
{
g.setStroke(new BasicStroke(40) );
g.setColor(Colo r.blue);
g.drawLine(0,20 +0*80,600,20+0* 80);
g.drawLine(0,20 +1*80,600,20+1* 80);
g.drawLine(0,20 +2*80,600,20+2* 80);
g.setColor(Colo r.blue);
g.fillRect(0,0, 200,200);
g.setColor(Colo r.white);
g.fillRect(0,80 ,200,40);
g.fillRect(80,0 ,40,200);
}
{
g.setStroke(new BasicStroke(40) );
g.setColor(Colo r.blue);
g.drawLine(0,20 +0*80,600,20+0* 80);
g.drawLine(0,20 +1*80,600,20+1* 80);
g.drawLine(0,20 +2*80,600,20+2* 80);
g.setColor(Colo r.blue);
g.fillRect(0,0, 200,200);
g.setColor(Colo r.white);
g.fillRect(0,80 ,200,40);
g.fillRect(80,0 ,40,200);
}
Comment