Question

JavaFX (50 Pts) r ins Use JavaFX Application to draw the American Flag (without the stars). It has thirteen alternatin,g red

Help, I would also want to know how to draw the stars as well please.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:::

package gui;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class US_Flag extends Application {
   @Override
   public void start(Stage primaryStage) {
       //--Set Properties
       Scene scene = new Scene(new USFlagPane());
       primaryStage.setTitle("US Flag");
       primaryStage.setScene(scene);
       primaryStage.setResizable(false);
       primaryStage.show();
   }
   public static void main(String[] args) {
       launch(args);
   }
}
class USFlagPane extends Pane {
   private static final double Pane_W = 718;
   private static final double Pane_H = 370;
   private static final double BG_W = 310;
   private static final double BG_H = 208;
   public USFlagPane() {
       this.setPrefSize(Pane_W, Pane_H);
       //--Red Stripes
       double y = 0;
       for (int i = 0; i < 7; i++) {
           Rectangle block = new Rectangle(0, y, 728, 208.0 / 7.0);
           block.setFill(Color.RED);
           y += 2 * 208.0 / 7;
           this.getChildren().add(block);
       }
       //--BackGround
       Rectangle StarBox = new Rectangle(0, 0, BG_W, BG_H);
       StarBox.setFill(Color.BLUE);
       this.getChildren().add(StarBox);
       //--Stars
       //--Import From Net


       //mention path of star here
       final String StarPath = "https://cs.stcc.edu/wp-content/uploads/2017/03/flagstar.png";
       Image image = new Image(StarPath);
       //--Controls 6x5
       for (int j = 0; j < 5; j++) {
           for (int i = 0; i < 6; i++) {
               ImageView star = new ImageView(image);
               star.setX((double) (i * 55 + 8));
               star.setY((double) (j * 40 + 12));
               star.setFitHeight(20.0);
               star.setFitWidth(20.0);
               this.getChildren().add(star);
           }
       }
       //--Controls 5x4
       for (int j = 0; j < 4; j++) {
           for (int i = 0; i < 5; i++) {
               ImageView star = new ImageView(image);
               star.setX((double) (i * 55 + 35));
               star.setY((double) (j * 40 + 32));
               star.setFitHeight(20.0);
               star.setFitWidth(20.0);
               this.getChildren().add(star);
           }
       }
   }
   public static void main(String[] args) {
       Application.launch((String[])args);
   }
}

output:

y+= 2 * 208.0 / 7; US Hac] flag this.getChildren ().add (star);

in order to draw star , Just download image of star and give the path of it to the as mentioned in the comments

Add a comment
Know the answer?
Add Answer to:
Help, I would also want to know how to draw the stars as well please. JavaFX (50 Pts) r ins Use JavaFX Application to draw the American Flag (without the stars). It has thirteen alternatin,g red and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT