Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Change the circles to start

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    41
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Change the circles to start

    Im trying to change the circle in the flag to stars
    tried every possible way i know nothing worked
    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;
            }
     
     
        }
    }


  2. #2
    Member
    Join Date
    Oct 2010
    Posts
    40
    Thanks
    0
    Thanked 2 Times in 1 Post

    Default Re: Change the circles to start

    your hint is between these lines. try changing the fillOval method to fillRect and you get rectangles instead of ovals. now find a way to draw the stars using drawPolygon method.

    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;
            }

Similar Threads

  1. [SOLVED] Help with my Java program: Applet that draws 5 random circles.
    By iDizzle in forum What's Wrong With My Code?
    Replies: 20
    Last Post: March 27th, 2012, 02:20 AM
  2. Replies: 1
    Last Post: February 10th, 2012, 07:01 AM
  3. Replies: 3
    Last Post: May 21st, 2011, 09:47 AM
  4. Help with creating random circles
    By cool48 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 5th, 2011, 10:18 AM
  5. Drawing circles with smoother lines?
    By tabutcher in forum Java Theory & Questions
    Replies: 4
    Last Post: April 18th, 2010, 11:12 AM