import javafx.application.Application; import javafx.scene.control.CheckBox; imp
ID: 3815834 • Letter: I
Question
import javafx.application.Application;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Slider;
import javafx.stage.Stage;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.paint.Color;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.util.Duration;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
public class n01059882 extends RectangleSlider
{
public static void main(String[] args)
{
launch(args);
}
}
class MyName extends Application
{
protected Text text = new Text(70, 110, "Samuel Silveira");
protected BorderPane getPane()
{
HBox paneForButtons = new HBox(20);
Button btUp = new Button("Up");
Button btDown = new Button("Down");
paneForButtons.getChildren().addAll(btUp, btDown);
paneForButtons.setAlignment(Pos.CENTER);
paneForButtons.setStyle("-fx-border-color: blueviolet");
BorderPane pane = new BorderPane();
pane.setBottom(paneForButtons);
GridPane twoPanes = new GridPane();
twoPanes.setHgap(10);
twoPanes.setVgap(10);
twoPanes.setPadding(new Insets(0, 10 , 0, 10));
pane.setCenter(twoPanes);
Pane paneForText = new Pane();
paneForText.getChildren().add(text);
twoPanes.add(paneForText, 0, 0);
btUp.setOnAction(e -> text.setY(text.getY() - 10));
btDown.setOnAction(e -> text.setY(text.getY() + 10));
return pane;
}
@Override
public void start(Stage primaryStage)
{
Scene scene = new Scene(getPane(), 800, 600);
primaryStage.setTitle("Final Project");
primaryStage.setScene(scene);
primaryStage.show();
}
}
class CheckBoxes extends MyName
{
@Override
protected BorderPane getPane()
{
BorderPane pane = super.getPane();
Font fontBoldItalic = Font.font("Verdana", FontWeight.BOLD, FontPosture.ITALIC, 20);
Font fontBold = Font.font("Verdana", FontWeight.BOLD, FontPosture.REGULAR, 20);
Font fontItalic = Font.font("Verdana", FontWeight.NORMAL, FontPosture.ITALIC, 20);
Font fontNormal = Font.font("Verdana", FontWeight.NORMAL, FontPosture.REGULAR, 20);
text.setFont(fontNormal);
VBox paneForCheckBoxes = new VBox(20);
paneForCheckBoxes.setPadding(new Insets(5, 5, 5, 5));
paneForCheckBoxes.setStyle("-fx-border-color: blueviolet");
CheckBox chkBold = new CheckBox("Bold");
CheckBox chkItalic = new CheckBox("Italic");
paneForCheckBoxes.getChildren().addAll(chkBold, chkItalic);
pane.setLeft(paneForCheckBoxes);
EventHandler<ActionEvent> handler = e ->
{
if(chkBold.isSelected() && chkItalic.isSelected())
{
text.setFont(fontBoldItalic);
}
else if (chkBold.isSelected())
{
text.setFont(fontBold);
}
else if (chkItalic.isSelected())
{
text.setFont(fontItalic);
}
else
{
text.setFont(fontNormal);
}
};
chkBold.setOnAction(handler);
chkItalic.setOnAction(handler);
return pane;
}
}
class RadioButtons extends CheckBoxes
{
@Override
protected BorderPane getPane()
{
BorderPane pane = super.getPane();
VBox paneForRadioButtons = new VBox(20);
paneForRadioButtons.setPadding(new Insets(5,5,5,5));
paneForRadioButtons.setStyle("-fx-border-color: blueviolet");
paneForRadioButtons.setStyle("-fx-border-width: 2px; -ffx-border-color: blueviolet");
RadioButton rbCrimson = new RadioButton("CRIMSON");
RadioButton rbPeru = new RadioButton("PERU");
RadioButton rbIndigo = new RadioButton("INDIGO");
paneForRadioButtons.getChildren().addAll(rbCrimson, rbPeru, rbIndigo);
pane.setRight(paneForRadioButtons);
ToggleGroup group = new ToggleGroup();
rbCrimson.setToggleGroup(group);
rbPeru.setToggleGroup(group);
rbIndigo.setToggleGroup(group);
rbCrimson.setOnAction(e ->
{
if(rbCrimson.isSelected())
{
text.setFill(Color.CRIMSON);
}
});
rbPeru.setOnAction(e ->
{
if(rbPeru.isSelected())
{
text.setFill(Color.PERU);
}
});
rbIndigo.setOnAction(e ->
{
if(rbIndigo.isSelected())
{
text.setFill(Color.INDIGO);
}
});
return pane;
}
}
class RectanglePane extends Pane
{
public final double width = 30;
public final double height = 15;
private double x = width, y = height;
private double dx = 1, dy = 1;
private Rectangle rectangle = new Rectangle(x, y);
private Timeline animation;
public RectanglePane()
{
rectangle.setFill(Color.RED);
getChildren().add(rectangle);
animation = new Timeline(new KeyFrame(Duration.millis(50), e -> moveRectangle()));
animation.setCycleCount(Timeline.INDEFINITE);
animation.play();
}
public void play()
{
animation.play();
}
public void pause()
{
animation.pause();
}
public void increaseSpeed()
{
animation.setRate(animation.getRate() + 0.1);
}
public void decreaseSpeed()
{
animation.setRate(animation.getRate() > 0 ? animation.getRate() - 0.1 : 0);
}
public DoubleProperty rateProperty()
{
return animation.rateProperty();
}
protected void moveRectangle()
{
if (x < width || x > getWidth() - width)
{
dx *= -1;
}
if (y < height || y > getHeight() - height)
{
dy *= -1;
}
x += dx;
y += dy;
rectangle.setX(x);
rectangle.setY(y);
}
}
class MediaDemo extends RectangleSlider {
@Override
protected BorderPane getPane(){
BorderPane pane = super.getPane();
final String MEDIA_URL = "http://www.unf.edu/~n01059882/029.mp4";
Media media = new Media(MEDIA_URL);
MediaPlayer mediaPlayer = new MediaPlayer(media);
MediaView mediaView = new MediaView(mediaPlayer);
mediaView.setFitWidth(320);
mediaView.setFitHeight(420);
mediaView.setPreserveRatio(false);
Button playButton = new Button(">");
playButton.setOnAction(e -> {
if (playButton.getText().equals(">")) {
mediaPlayer.play();
playButton.setText("||");
} else {
mediaPlayer.pause();
playButton.setText(">");
}
});
Button rewindButton = new Button("<<");
rewindButton.setOnAction(e -> mediaPlayer.seek(Duration.ZERO));
Slider slVolume = new Slider();
slVolume.setPrefWidth(150);
slVolume.setMaxWidth(Region.USE_PREF_SIZE);
slVolume.setMinWidth(30);
slVolume.setValue(50);
mediaPlayer.volumeProperty().bind(
slVolume.valueProperty().divide(100));
HBox hBox = new HBox(10);
hBox.setAlignment(Pos.CENTER);
hBox.getChildren().addAll(playButton, rewindButton,
new Label("Volume"), slVolume);
BorderPane vpane = new BorderPane();
vpane.setCenter(mediaView);
vpane.setBottom(hBox);
pane.setCenter(vpane);
//twoPanes.setRight(vpane);
return pane;
}
}
class RectangleSlider extends RadioButtons
{
@Override
protected BorderPane getPane()
{
BorderPane pane = super.getPane();
RectanglePane rectanglePane = new RectanglePane();
Slider slSpeed = new Slider();
slSpeed.setMax(20);
rectanglePane.rateProperty().bind(slSpeed.valueProperty());
BorderPane rPane = new BorderPane();
rPane.setTop(rectanglePane);
rPane.setBottom(slSpeed);
pane.setTop(rPane);
return pane;
}
}
To the same person that helped me with this code:
I need a help with following the order of inheritance of the classes, which class inherit the other. Please explain and show how it is done. Another thing is how do I save my mp4 file in a URL in order to display it in the pane
Thank you
Explanation / Answer
1. RectangleSlider class inherits the properties of RadioButtons class
2. n01059882 class inherits the properties of RectangleSlider class
3. MyName class inherits the properties of Application class
4. CheckBoxes class inherits the properties of MyName class
5. Application is super class
6. RectanglePane class inherits the properties of Pane class
7. MediaDemo class inherits the properties of RectangleSlider class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.