0

Hello i'm not that great of a coder. I recently tried out a code showing dxball scenerio which is very simple. There i wanted to print a text as well showing "score:0". I'm giving my code below [It compiles fine, but shows runtime error], on my friends' computer it runs without any error showing the text on the output screen.

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.Font;

public class dxball extends Application{

    public void start(Stage stage){

        Group root= new Group();
        Scene scene=new Scene(root,700,500);
        Text t=new Text(20,20,"Score:0");
        t.setFont(Font.font("Verdana", 20));
        t.setFill(Color.BLACK);
        root.getChildren().add(t); 
        Circle ball=new Circle(340,455,15);
        ball.setFill(Color.CORNFLOWERBLUE);

        Rectangle brick1=new Rectangle(200,470,280,30);
        brick1.setFill(Color.PALEGREEN);
        brick1.setStroke(Color.CYAN);

        Rectangle brick2=new Rectangle(100,100,80,40);
        brick2.setFill(Color.CORAL);
        brick2.setStroke(Color.BLACK);

        Rectangle brick3=new Rectangle(200,100,80,40);
        brick3.setFill(Color.CORAL);
        brick3.setStroke(Color.BLACK);

        Rectangle brick4=new Rectangle(300,100,80,40);
        brick4.setFill(Color.CORAL);
        brick4.setStroke(Color.BLACK);

        Rectangle brick5=new Rectangle(400,100,80,40);
        brick5.setFill(Color.CORAL);
        brick5.setStroke(Color.BLACK);

        Rectangle brick6=new Rectangle(500,100,80,40);
        brick6.setFill(Color.CORAL);
        brick6.setStroke(Color.BLACK);

        Rectangle brick7=new Rectangle(250,150,80,40);
        brick7.setFill(Color.CYAN);
        brick7.setStroke(Color.BLACK);

        Rectangle brick8=new Rectangle(350,150,80,40);
        brick8.setFill(Color.CYAN);
        brick8.setStroke(Color.BLACK);

        root.getChildren().add(brick1);
        root.getChildren().add(brick2);
        root.getChildren().add(brick3);
        root.getChildren().add(brick4);
        root.getChildren().add(brick5);
        root.getChildren().add(brick6);        
        root.getChildren().add(brick7);
        root.getChildren().add(brick8);
        root.getChildren().add(ball);

        stage.setTitle("Untitled");
        stage.setScene(scene);
        stage.show();
    }

}

Please help :( i'm attaching the pic when i try to run the code what appears enter image description here

James_D
  • 201,275
  • 16
  • 291
  • 322
  • 1
    Please include the stack trace as text in your question, not as a link to a screenshot. This looks like a font issue. Which JDK version are you using? – James_D Apr 17 '16 at 19:57
  • it looks like you don't have the font installed on you computer which you are calling. – Blip Apr 17 '16 at 19:59
  • FWIW, the provided application code runs fine for me without any exceptions on OS X 10.9.5 and Java 8u72. – jewelsea Apr 19 '16 at 01:49
  • @James_D: JDK 8 & i checked, the font "Verdana" exists in my system. –  Apr 19 '16 at 16:50
  • @Blip : The error still occurs if i try to run the code without setting that font. –  Apr 19 '16 at 16:51

1 Answers1

0

Its not because of JDK version. May be because of font which you used isn't exist in your system. It worked for me fine. Check whether Verdana.tff file exists in

C:\Windows\Fonts

directory. If not install it and run.

Venkat Prasanna
  • 692
  • 4
  • 16
  • According to the [documentation](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/text/Font.html#font-java.lang.String-double-), if the font doesn't exist on the system, then `Font.font(...)` is supposed to substitute an appropriate one that is available. So this looks like a JavaFX bug. In that sense, it may actually be a JDK version issue. You can't really expect the developer to ensure the font is installed on all possible users' machines. – James_D Apr 18 '16 at 13:09
  • A developer could [include the font as a resource with their application distribution](http://stackoverflow.com/questions/16855677/how-to-embed-ttf-fonts-is-javafx-2-2), though it would be necessary to check licensing distribution rights for a given font to do that legally. – jewelsea Apr 19 '16 at 01:47
  • @prasanna I checked, the font exists in my C drive. –  Apr 19 '16 at 16:53