import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
////////// Flag
class AmericanFlag
{
///////// main
public static void main(String[] args)
{
JFrame windo = new FlagWindow();
windo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
windo.setVisible(true);
}//end main
}//end Flag
///////////FlagWindow
class FlagWindow extends JFrame {
//////Constructor
FlagWindow() {
Container content = this.getContentPane();//get content pane
content.setLayout(new BorderLayout());//set its layout
drawString drawing = new drawString();//Create a drawing
content.add(drawing, BorderLayout.CENTER);//center expands
this.setTitle("The United States Flag");
this.pack();
}//end constructor
}// end class Flag
//////// class MyDrawing
//this class extends JPaneland overrides paintcomponent to
//create a component for drawing - in this case the U.S. flag
class drawString extends JPanel
{
///////Constructor
drawString()
{
setPreferredSize(new Dimension(800, 600));//initial screen sizes
setBackground(Color.white);//sets the background color
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
int w = getWidth();
int h = getHeight();
int stripeHeigth = h*4/65;
int y = stripeHeigth;
int x;
g.setColor(Color.red);//setting red stripes across the flag
g.fillRect(w/10, h/10, w*4/5, h*4/5);
g.setColor(Color.white);//setting white stripes across the flag
while (y < h*7/10) {
g.fillRect(w/10, h/10 + y, w*4/5, h*4/65);
y = y + (stripeHeigth*2);
}
g.setColor(Color.blue);//setting a blue panel to be filled with stars
g.fillRect(w/10, h/10, w*8/25, h*28/65);
g.setColor(Color.white);///color to be used for 50 stars
x = h*85/650;
y = w/10+w*28/2325;
while (y < w*105/250) {
g.fillOval(y, x, w*4/200, w*4/200);
x += h*13/155;
g.fillOval(y, x, w*4/200, w*4/200);
x += h*13/155;
g.fillOval(y, x, w*4/200, w*4/200);
x += h*13/155;
g.fillOval(y, x, w*4/200, w*4/200);
x += h*13/155;
g.fillOval(y, x, w*4/200, w*4/200);
y+= w*128/2325;
x = h*85/650;
}
y = w/10+w*88/2325;
x = h*85/650+h*13/310;
while(y < w*95/250) {
g.fillOval(y, x, w*4/200, w*4/200);
x += h*13/155;
g.fillOval(y, x, w*4/200, w*4/200);
x += h*13/155;
g.fillOval(y, x, w*4/200, w*4/200);
x += h*13/155;
g.fillOval(y, x, w*4/200, w*4/200);
y+= w*128/2325;
x = h*85/650+h*13/310;
}
}
}