chanding scene in javafx scene bulider [duplicate] - javafx

This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 5 years ago.
I am trying to make a loading page in javafx scenebuilder but I get an error on the line rootPane.getChildren().setAll(pane),it underlines etChildren() and says it doesnt find the symbol,dont understant why that is.
package javafxapplication14;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
public class FXMLDocumentController implements Initializable {
private Label label;
private Object theStage;
private Object rootPane;
#Override
public void initialize(URL url, ResourceBundle rb) {
}
private void loadsecond(ActionEvent event) throws IOException {
AnchorPane pane=FXMLLoader.load(getClass().getResource("Second.fxml"));
rootPane.getChildren().setAll(pane);
}
}

The class Object can't handle .getChildren().

Related

Error when making a photo slideshow in JavaFX

I'm currently following a tutorial on YouTube to make a photo slide show in JavaFX. Here is my controller code:
import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import java.util.ResourceBundle;
public class Controller implements Initializable {
#FXML ImageView imageView;
int count;
public void slideshow()
{
ArrayList<Image> images= new ArrayList<Image>();
images.add(new Image("b1.jpg"));
images.add(new Image("b2.jpg"));
images.add(new Image("b3.jpg"));
Timeline timeline=new Timeline(new KeyFrame(Duration.ofSeconds(5), event->{
imageView.setImage(images.get(count));
count++;
if (count==3)
count=0;
}));
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();
}
#Override
public void initialize(URL location,ResourceBundle recourses)
{
slideshow();
}
}
I have an error on this line:
Timeline timeline=new Timeline(new KeyFrame(Duration.ofSeconds(5), event->{
I want the application to display the next image after every 5 seconds.

KeyValue class gives error in javafx? how i fix it

KeyValue class gives error in javafx? I also implements all the abstract method but still face issue?
package at_collection;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
import javax.xml.crypto.dsig.keyinfo.KeyValue;
public class Scene1Controller implements Initializable {
#FXML
private StackPane parent;
#FXML
private AnchorPane child1;
#FXML
private Button btn1;
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
#FXML
private void load1(ActionEvent event) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Scene2.fxml"));
Scene scene = btn1.getScene();
root.translateYProperty().set(scene.getHeight());
parent.getChildren().add(root);
Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN); // Here is the problem
KeyFrame kf = new KeyFrame(Duration.seconds(1), kv);
timeline.getKeyFrames().add(kf);
timeline.setOnFinished(t -> {
parent.getChildren().remove(child1);
});
timeline.play();
}
}
The stack trace is not print. Because of the compile-time error. i'm actually implements this "https://www.youtube.com/watch?v=cqskg3DYH8g"
Here is the output of this code
This is because of the Wrong Import "import javax.xml.crypto.dsig.keyinfo.KeyValue"
Import this one "import javafx.animation.KeyValue;"

Blank window using Javafx

I made a window by using the screen builder program, but after I run it, only a white blank window appears. I think the problem that all variables , which are lblOUTPUT, aren't assigned. I'm a beginner at Scene builder and have been really struggling with this issue because it's my first work.
FXmain
package javaapplication6;
import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* #author ammar
*/
public class FXMain extends Application {
#Override
public void start(Stage stage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/javaapplication6/FXML.fxml"));
Scene scene = new Scene(root, 600, 400);
stage.setScene(scene);
stage.setTitle("Kilometer to miles converter");
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
FXMLcontroller:
enter code here
package javaapplication6;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
/**
* FXML Controller class
*
* #author ammar
*/
public class FXMLController implements Initializable {
#FXML
private Label lblOUTPUT;
#FXML
private Button btnCONVERT;
#FXML
private TextField txtKm;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
Ok, I solved after two hours of struggling, I just click the run button in the NetBeans (looks like a play button) and after that, right-click on the main class, then run the file, and it worked!.

'#FXML' not applicable to type

package sample;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import
public class tGenController implements Initializable {
Controller of a fxml
#FXML
//Error appears here says "#FXML" not applicable to type
private class generatePress() {
}
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
}
}
Error msg pop up on "#FXML" says "#FXML" not applicable type.
I through I did import all the required package but that still doesn't work.
There is a bit of mistake in your code. I think generatePress() is a function and you have defined it as a class.
Try this in your controller class -
#FXML private void generatePress(){
}
I cannot put a comment as I haven't enough reputation : why does your controller implements Initializable? Isn't it more convenient for you to use this code instead?
public class tGenController extends [Root] {
// [Root] is the main tag on your FXML file
#FXML
private void generatePress() {
//XXX
}
#FXML
public void initialize() {
//XXX
}
}

EventHandler error when I try to create a play button for a video media player in Java

I don't understand why eclipse won't recognize the EventHandler since I have imported it. Here is my code:
package application;
import java.awt.event.ActionEvent;
import com.sun.glass.ui.Accessible.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.media.MediaPlayer;
public class MediaBar extends HBox {
Slider time =new Slider();
Slider vol =new Slider();
Button playButton=new Button("||");
Label volume=new Label("Volume");
MediaPlayer player;
public MediaBar(MediaPlayer play){
player=play;
setAlignment(Pos.CENTER);
setPadding(new Insets(5,10,5,10));
vol.setPrefWidth(70);
vol.setMin(30);
vol.setValue(100);
HBox.setHgrow(time, Priority.ALWAYS);
playButton.setPrefWidth(30);
getChildren().add(playButton);
getChildren().add(time);
getChildren().add(volume);
getChildren().add(vol);
playButton.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent e){
Status status=player.getStatus();
if(status==Status.Playing){
if(player.getCurrentTime().greaterThanOrEqualTo(player.getTotalDuration())){
player.seek(player.getStartTime());
player.play();
}
else{
player.pause();
playerButton.setText(">");
}
}
if(status==Status.PAUSE ||status==Status.HALTED||status==Status.STOPPED){
player.play();
playButton.setText("||");
}
}
});
}
}
Here is the error message :
The type Accessible.EventHandler is not generic; it cannot be parameterized with arguments <ActionEvent>
What am I doing wrong?
Correct the import you are using JavaFX not Swing/AWT:
replace :
import java.awt.event.ActionEvent;
import com.sun.glass.ui.Accessible.EventHandler;
with :
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
Avoid automatic importing or pay attention to what you are importing !

Resources