IhateJava IhateJava - 22 days ago 5x
Java Question

javafx gui using ellipses's issues

I am new to javafx and am trying to make a GUI that has rings of ellipses of different sizes/colors similar to a dart board. the end goal is to make it an animation and have it spin and such but for now I am just trying to get the GUI to look/work properly before I add animation. My issue is when I run the program the GUI comes up blank/empty. I'm not sure as of why so if you guys see something that I don't and have any tips to a rookie please by all means let me know!here is the code I have written so far:

package targetpractice;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.stage.Stage;

public class targetpractice extends Application {

private Ellipse[] rings;
private Color[] colors = {Color.BLUE, Color.RED, Color.YELLOW};
private final int NUMCOLORS = 3;

double width = 0;
double height = 0;
int numRings = 0;

public void start(Stage primaryStage) {
Pane pane = new Pane();

rings = new Ellipse[numRings];
for (int ringNum = numRings - 1; ringNum >= 0; ringNum--) {
Ellipse e = new Ellipse(width / 2, height / 2, ringNum * (0.5 * width / numRings), ringNum * (0.5 * height / numRings));
e.setFill(colors[ringNum % NUMCOLORS]);
rings[ringNum] = e;

Scene scene = new Scene(pane, 600, 400);
primaryStage.setTitle("target practice");

* @param args the command line arguments
public static void main(String[] args) {



You are initializing ringNum in the for loop to -1, and iterating as long as it is >=0. I.e. you are not iterating at all. Similarly, you initialize the rings array to an array of zero items.

Presumably you actually wanted to set numRings to something other than zero. Similarly, you probably want to initialize the values of other variables to something sensible as well.