Greek Flag

I would like to create a class that extends JComponent. I need to draw the Greek flag,

For this flag, the ratio of width to height is 11:8, so for example 220 pixels by 160. It needs to be drawn as large as possible depending on the applet window but still keeping the ratio.

I have done the starting code and I am able to draw the flag however I have to clue in how to do the ration part. Any suggestions?

import javax.swing.JComponent;

import java.awt.*;

import java.awt.geom.Ellipse2D;

class GreekFlagextends JComponent

{

publicvoid 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

{

}

// then draw the rows, and the cross

}

}

[1668 byte] By [Disco_Stua] at [2007-11-26 19:02:53]
# 1
You need to set the size of the flag to the smaller (ratio wise) side, whether it is width or height.
zadoka at 2007-7-9 20:49:28 > top of Java-index,Security,Cryptography...
# 2
Okay so I will use that to find the size of the applet window. However how will I be able to stop the flag expanding into the space? As I need to keep the ration of 11:8?
Disco_Stua at 2007-7-9 20:49:28 > top of Java-index,Security,Cryptography...
# 3
Work out your example on paper. If the space you have is 220 pixels by 160 then how big should your flag be?Then go back and look at the math you did to get that answer. It should be easy to translate that into a few lines of code to get width and height to paint.
zadoka at 2007-7-9 20:49:28 > top of Java-index,Security,Cryptography...
# 4
cheers i will try and use my maths skills. :)
Disco_Stua at 2007-7-9 20:49:28 > top of Java-index,Security,Cryptography...
# 5
i dont really have clue how to do this! any help would most appreciated .
Disco_Stua at 2007-7-9 20:49:28 > top of Java-index,Security,Cryptography...
# 6

> i dont really have clue how to do this! any help

> would most appreciated .

This example should nudge you:

You have a 800 x 500 area to display the flag.

You have a ratio or 11:8.So if you made the flag as wide as the screen then your height would be = 800* (8/11) which is 581.This is bigger than your height so instead you would need to use 500 as a height.So a 500 tall flag would be 500 * (11/8) = wide which is 687.5.

zadoka at 2007-7-9 20:49:28 > top of Java-index,Security,Cryptography...