Question

PP 3.13 Write a JavaFX application that draws a circle centered at poinit (200, 200) with a random radius in the range 50 to

PP.15

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  1. package lab.random;
  2. import javafx.application.Application;
  3. import javafx.scene.Scene;
  4. import javafx.scene.layout.BorderPane;
  5. import javafx.scene.paint.Color;
  6. import javafx.scene.paint.Paint;
  7. import javafx.scene.shape.Reactangle;
  8. import javafx.scene.shape.Shape;
  9. import javafx.stage.Stage;
  10. import java.util.Random;
  11. /**
  12. *It is a javafx application to draw a rectangle.
  13. *The rectangle will be filled with a different color at every launch.
  14. */
  15. public class RandomColor extends Application {
  16. public static void main(String[] args) {
  17. launch(args);
  18. }
  19. @Override
  20. public void start(Stage stage) throws Exception {
  21. BorderPane root = new BorderPane();
  22. stage.setMaxHeight(350);
  23. stage.setMaxWidth(350);
  24. stage.setResizable(false);
  25. Scene scene = new Scene(root, stage.getMaxWidth(), stage.getMaxHeight());
  26. stage.setScene(scene);
  27. Rectangle rectangle = createRectangle();
  28. rectangle.setFill(randomColour());
  29. root.setCenter(rectangle);
  30. stage.show();
  31. }
  32. /**
  33. Creates a rectangle
  34. */
  35. private Rectangle createRectangle() {
  36. Rectangle rectangle = new Rectangle(150);
  37. return rectangle;
  38. }
  39. /**
  40. Create random color every time the method is called.
  41. */
  42. public Paint randomColor() {
  43. Random random = new Random();
  44. int r = random.nextInt(255);
  45. int g = random.nextInt(255);
  46. int b = random.nextInt(255);
  47. return Color.rgb(r, g, b);
  48. }
  49. }
Add a comment
Know the answer?
Add Answer to:
PP.15 PP 3.13 Write a JavaFX application that draws a circle centered at poinit (200, 200) with a random radius in the range 50 to 150. Each time the program is run it will draw a different circle. P...
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
ADVERTISEMENT