2017-02-17 7 views
-1

ok私は色の異なる同心円を持つアーチェリースタイルのターゲットを作成しようとしていますが、事物は色々な色で各円を塗りつぶすことができません。色をつけて次の円に移動すると、前の円でも色が他の円の色に変わります。どのように色を塗りつぶすのですか?ここに私のコードはここではJavaFXのソリューションです色がJavaの同心円

public void paint(Graphics g){ 

      int fontSize = 20; 

      g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); 
      g.setColor(Color.yellow); 
      g.drawArc(250, 150, 50, 50, 0, 360); 
      g.fillArc(250, 150, 50, 50, 0, 360); 
      g.setColor(Color.red); 

      g.drawArc(230, 130, 90, 90, 0, 360); 
      g.setColor(Color.blue); 
      g.drawArc(210, 110, 130, 130, 0, 360); 
      g.fillArc(210, 110, 130, 130, 0, 360); 
      g.setColor(Color.black); 
      g.drawArc(190, 90, 170, 170, 0, 360); 
      g.fillArc(190, 90, 170, 170, 0, 360); 

    } 
+2

が、あなたは小さな円を超える大きな円を描いています。そして、簡単に 'fillOval'を使いましょう。 –

+1

カスタムペイントは、paint(...)ではなく、 'paintComponent(...)'をオーバーライドして行う必要があります。 – camickr

答えて

0

です:円を描くの順序を逆に

import javafx.application.Application; 
import javafx.event.EventHandler; 
import javafx.scene.Scene; 
import javafx.scene.layout.Pane; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.Ellipse; 
import javafx.scene.shape.Rectangle; 
import javafx.stage.Stage; 
import javafx.stage.WindowEvent; 

public class Lab8 extends Application { 

    private Pane pane; 

    @Override 
    public void start(Stage primaryStage) throws Exception { 
     pane = new Pane(); 

     int pwidth = 425; 
     int pheight = 425; 
     int cx = 210; 
     int cy = 210; 

     Rectangle r = new Rectangle(); 
     r.setX(0); 
     r.setY(0); 
     r.setWidth(pwidth); 
     r.setHeight(pheight); 
     r.setFill(Color.web("#00ffff")); 
     pane.getChildren().add(r); 

     Ellipse c0 = new Ellipse(cx,cy,205,205); 
     c0.setFill(Color.WHITE); 
     c0.setStroke(Color.BLACK); 
     pane.getChildren().add(c0); 

     c0 = new Ellipse(cx,cy,185,185); 
     c0.setFill(Color.WHITE); 
     c0.setStroke(Color.BLACK); 
     pane.getChildren().add(c0);  

     c0 = new Ellipse(cx,cy,165,165); 
     c0.setFill(Color.BLACK); 
     c0.setStroke(Color.WHITE); 
     pane.getChildren().add(c0);  

     c0 = new Ellipse(cx,cy,145,145); 
     c0.setFill(Color.BLACK); 
     c0.setStroke(Color.WHITE); 
     pane.getChildren().add(c0);     

     c0 = new Ellipse(cx,cy,125,125); 
     c0.setFill(Color.BLUE); 
     c0.setStroke(Color.BLACK); 
     pane.getChildren().add(c0); 

     c0 = new Ellipse(cx,cy,105,105); 
     c0.setFill(Color.BLUE); 
     c0.setStroke(Color.BLACK); 
     pane.getChildren().add(c0); 

     c0 = new Ellipse(cx,cy,85,85); 
     c0.setFill(Color.RED); 
     c0.setStroke(Color.BLACK); 
     pane.getChildren().add(c0); 

     c0 = new Ellipse(cx,cy,65,65); 
     c0.setFill(Color.RED); 
     c0.setStroke(Color.BLACK); 
     pane.getChildren().add(c0); 

     c0 = new Ellipse(cx,cy,45,45); 
     c0.setFill(Color.YELLOW); 
     c0.setStroke(Color.BLACK); 
     pane.getChildren().add(c0); 

     c0 = new Ellipse(cx,cy,25,25); 
     c0.setFill(Color.YELLOW); 
     c0.setStroke(Color.BLACK); 
     pane.getChildren().add(c0); 

     c0 = new Ellipse(cx,cy,5,5); 
     c0.setFill(Color.BLACK); 
     c0.setStroke(Color.WHITE); 
     pane.getChildren().add(c0);   

     Scene scene = new Scene(pane,pwidth,pheight); 
     primaryStage.setTitle("Target"); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
     primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { 
      public void handle(WindowEvent we) { 
       //stage is closing 
       System.out.println("Bye."); 
      } 
     }); 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

enter image description here