Can't instantiate Path() class on Javafx 2.0 - java

I'm learning javafx.
I'm trying to make a path, but when i instantiate the class Path(), i receive the following message: "java.nio.file.Path is abstract; cannot be instantiated"
package mapas;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.BoxBlur;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.StrokeType;
import javafx.stage.Stage;
import java.nio.file.Path;
import javax.sound.midi.Patch;
public class Mapas extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
Group root = new Group();
Group circles = new Group();
Scene scene = new Scene(root, 800, 600, Color.BLACK);
primaryStage.setScene(scene);
circles.setEffect(new BoxBlur(10, 10, 3));
primaryStage.show();
for(int i = 0; i < 30; i++){
Circle circle = new Circle(150, Color.web("white", 0.05));
circle.setStrokeType(StrokeType.OUTSIDE);
circle.setStroke(Color.web("white", 0.16));
circle.setStrokeWidth(4);
circles.getChildren().add(circle);
}
root.getChildren().add(circles);
Path path = new Path(); // <-- error
}
}
What's wrong?

Are you sure you want to import java.nio.file.Path as opposed to javafx.scene.shape.Path?????

Related

Cannot change the width of a button below a certain minimum

I have this code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ToggleButton;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;
public class ToggleButtonSize extends Application {
#Override
public void start(Stage stage) throws Exception {
var toggleButton = new ToggleButton();
toggleButton.setMaxHeight(10);
toggleButton.setMaxWidth(10);
// tried also
toggleButton.setStyle("-fx-max-width: 10; -fx-pref-width: 10;");
var pane = new FlowPane(toggleButton);
var scene = new Scene(pane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
This code works fine, but when I use MobileApplication instead the minimum width does not go to 10:
How can I shrink the size like when using Application?

Javafx: How to use a driver file for a source file to show shape created

I'm trying to understand the driver file I've been given for a certain problem I'm working on. I just started learning javafx and I'm try to create a shape inside the driver file, but the extra code of initializing, mouse events, etc. are in the source file. I created a function that returns the initialized X for the rectangle and a system.out.println in my driver file so I know they are connected. However whenever I run my driver file, I get a blank screen without the shape on it. Could someone tell me what I'm doing wrong with the scene/root/stage showing.
Heres my Code:
Multishape.java:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Multishape extends Group {
//Declaring variables here gives them greater scope
private Rectangle rectangle;
private Circle circle;
Group root = new Group();
public Multishape (double x, double y, double len){
rectangle = new Rectangle(len, len, Color.BLUE);
rectangle.setX(x);
rectangle.setY(y);
circle = new Circle(len, Color.RED);
}
//#Override
public void start(Stage primaryStage) {
//rectangle.setOnMouseClicked(handleMouseClick);//Set mouse click handler
//circle.setOnMouseClicked(handleMouseClick);//Set mouse click handler
root.getChildren().add(rectangle);//Set initial shape.
Scene scene = new Scene(root, 500, 500);
primaryStage.setScene(scene);
primaryStage.show();
}
double getLen(){
return (rectangle.getX());
}
}
MultishapeDriver.java:
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.input.KeyEvent;
import javafx.event.EventHandler;
public class MultishapeDriver extends Application
{
public static void main(String[] args)
{
launch(args);
}
public void start(Stage stage)
{
stage.setTitle("Multishape lab");
Group root = new Group();
Multishape shape = new Multishape(320, 240, 40);
root.getChildren().add(shape);
//stage.addEventHandler(KeyEvent.KEY_TYPED, shape.getKeyHandler());
System.out.println(shape.getLen());
stage.setScene(new Scene(root, 640, 480));
stage.show();
}
}
Your Multishape is a container of type Group.
But in its constructor, you only create 2 objects, you never adde them to your multishape.
Sou you'll need to add them with getChildren().add(rectangele), etc to your multishape.
Your Multishape constructor would then look like this:
public Multishape (double x, double y, double len){
rectangle = new Rectangle(len, len, Color.BLUE);
rectangle.setX(x);
rectangle.setY(y);
circle = new Circle(len, Color.RED);
getChildren().add(rectangle);
getChildren().add(circle);
}

JavaFX; Eclipse points error at main method

I was trying to learn JavaFX and used the code on this video: https://www.youtube.com/watch?v=FLkOX4Eez6o.
I have Google it but could not find a solution.
Then Eclipse IDE shows this error:
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.StackPane;
import javafx.stage.Stage;
public class Testes extends Application{
Button botao;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Controle de processos");
botao = new Button();
botao.setText("+");
StackPane layout = new StackPane();
layout.getChildren().add(botao);
Scene cena = new Scene(layout, 300, 250);
primaryStage.setScene(cena);
primaryStage.show();
}
}

Javafx 8 Font converts text to upper case A's

I have a problem using custom Fonts in Javafx 8.
Whenever I try to display a text it gets convertet to upper case A's
my code goes as follows:
package main;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class Main extends Application {
private Canvas can;
private GraphicsContext gc;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
Pane root = new Pane();
Scene scene = new Scene(root, 800, 400);
stage.setTitle("Test");
can = new Canvas(scene.getWidth(), scene.getHeight());
gc = can.getGraphicsContext2D();
root.getChildren().add(can);
stage.setResizable(false);
stage.setScene(scene);
stage.show();
InputStream is = Main.class.getResourceAsStream("Font/SSF4ABUKET.ttf");
Font font = Font.loadFont(is, 30);
gc.setFont(font);
gc.setFill(Color.RED);
gc.fillText("This is a test", 10, 200);
}
}
If I try this Font in a normal Text Editor (e.g. Open Office) it works perfectly fine.
Thanks for your help in advance.

JFX8 Mixed 2D and 3D, Scene Subscene incorrect drawing 3ds-file

Have some problems with using mixed 2D and 3D when i'm implementing a SubScene to my Scene.
You can see the problem by clicking the links. Im using the Interactivemesh-Modelimporter.
http://s3.postimg.org/nsef8o1f3/without_Subscene.png
http://s3.postimg.org/y16wehpgv/with_Subscene.png
import com.interactivemesh.jfx.importer.ImportException;
import com.interactivemesh.jfx.importer.tds.TdsModelImporter;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Camera;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SubScene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;
public class JavaFX7 extends Application {
HBox hBoxControls;
Group model3D;
double y_Axis;
double x_Axis;
double rotate;
public Rotate cameraXRotate;
public Rotate cameraYRotate;
public Translate cameraPosition2;
Camera camera;
public void controls() {
...
...
}
public void model () {
//
// importing 3ds Modell
//
TdsModelImporter myModel = new TdsModelImporter();
try {
String path = "C:/Users/Corvin/Downloads/DUC916_L.3DS/DUC916_L.3DS";
myModel.read(path);
}
catch (ImportException e)
{
System.out.println("Error importing 3ds model: "+e.getMessage());
return;
}
final Node[] myMesh = myModel.getImport();
myModel.close();
model3D = new Group(myMesh);
}
public static void main(String[] args) {
launch();
}
#Override
public void start(Stage stage) throws Exception {
y_Axis = 0.0;
controls();
model();
Camera camera = new PerspectiveCamera();
//-------------------
cameraXRotate = new Rotate(-5,Rotate.X_AXIS);
cameraYRotate = new Rotate(-50,Rotate.Y_AXIS);
cameraPosition2 = new Translate(0,-1900,-14000);
camera.getTransforms().add(cameraXRotate);
camera.getTransforms().add(cameraYRotate);
camera.getTransforms().add(cameraPosition2);
//-------------------
Pane sub = new Pane();
AnchorPane root = new AnchorPane();
AnchorPane.setRightAnchor(hBoxControls, 10.0);
AnchorPane.setBottomAnchor(hBoxControls, 10.0);
root.getChildren().add(hBoxControls);
// ---------------------------------------
Scene scene = new Scene(root, 800, 600, true);
SubScene subScene = new SubScene (sub, 800, 600);
subScene.setCamera(camera);
sub.getChildren().add(model3D);
root.getChildren().add(subScene);
stage.setScene(scene);
stage.show();
}
}
You are using 3D models.
That means your subscene needs a deapthBuffer not your primary scene. Thats why it works on the primary scene.
Change
SubScene subScene = new SubScene (sub, 800, 600);
to
SubScene subScene = new SubScene(sub, 800, 600,true, SceneAntialiasing.DISABLED);
(SceneAntialiasing.DISABLED or SceneAntialiasing.BALANCED)

Categories