import java.util.ArrayList;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class MovieApp extends Application{
String deleted_movies = "";
public boolean iftrue(String m, ArrayList<String> fruits)
{
for(String isThere: fruits)
{
if(isThere.equals(m))
{
return true;
}
else {
return false;
}
}
return false;
}
@Override
public void start(Stage primaryStage){
Pane aPane = new Pane();
TextField newItemField = new TextField();
newItemField.relocate(10, 10);
newItemField.setPrefSize(150, 25);
aPane.getChildren().add(newItemField);
Button addButton = new Button("AddMovies");
addButton.relocate(175, 10);
addButton.setPrefSize(100, 25);
aPane.getChildren().add(addButton);
Button removeButton = new Button("DeleteMovies");
removeButton.relocate(175, 45);
removeButton.setPrefSize(100, 25);
aPane.getChildren().add(removeButton);
ListView<String> fruitList = new ListView<String>();
ArrayList<String> fruits = new ArrayList<>();
fruits.add("James George");
fruits.add("What is my name");
fruits.add("Kedu Ihe icho");
fruits.add("Anom eba");
fruitList.setItems(FXCollections.observableArrayList(fruits));
fruitList.relocate(10, 45);
fruitList.setPrefSize(150, 150);
aPane.getChildren().add(fruitList);
addButton.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
String movieName = newItemField.getText().toString().trim();
boolean movieExists = iftrue(movieName,fruits);
if(!movieExists){
fruits.add(movieName);
fruitList.setItems(FXCollections.observableArrayList(fruits));
newItemField.setText("");
}
else{
newItemField.setText("The movie Exists");
}
}
});
removeButton.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
fruits.remove(deleted_movies);
fruitList.setItems(FXCollections.observableArrayList(fruits));
deleted_movies = "";
}
});
fruitList.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
deleted_movies = fruitList.getSelectionModel().getSelectedItem();
}
});
primaryStage.setTitle("My Movie List");
primaryStage.setScene(new Scene(aPane, 285, 205));
primaryStage.show();
}
public static void main(String [] args)
{
launch(args);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.