Question
Code in java import javafx.application.Application; import javafx.collections.FXCollections; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.Pane; import javafx.stage.Stage; import javafx.scene.control.Label; import javafx.scene.control.ListView; public class BorderPaneExampleApp extends Application {
Code in java
import javafx.application.Application; import javafx.collections.FXCollections; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.Pane; import javafx.stage.Stage; import javafx.scene.control.Label; import javafx.scene.control.ListView;
public class BorderPaneExampleApp extends Application { private DVDCollection model; private ListView
public BorderPaneExampleApp() { model = DVDCollection.example1(); }
public void start(Stage primaryStage) { Pane aPane = new Pane();
// Create the labels Label label1 = new Label("Title"); label1.relocate(10, 10); Label label2 = new Label("Year"); label2.relocate(220, 10); Label label3 = new Label("Length"); label3.relocate(290, 10);
// Create the lists tList = new ListView
yList = new ListView
lList = new ListView
// Create the button pane Pane buttonPane = new Pane();
// Create the buttons Button addButton = new Button("Add"); addButton.setStyle("-fx-font: 12 arial; -fx-base: rgb(0,100,0); -fx-text-fill: rgb(255,255,255);"); addButton.relocate(0, 0); addButton.setPrefSize(90,30);
Button deleteButton = new Button("Delete"); deleteButton.setStyle("-fx-font: 12 arial; -fx-base: rgb(200,0,0); -fx-text-fill: rgb(255,255,255);"); deleteButton.relocate(95, 0); deleteButton.setPrefSize(90,30);
Button statsButton = new Button("Stats"); statsButton.setStyle("-fx-font: 12 arial;"); statsButton.relocate(210, 0); statsButton.setPrefSize(90,30);
// Add all three buttons to the pane buttonPane.getChildren().addAll(addButton, deleteButton, statsButton); buttonPane.relocate(30, 200); buttonPane.setPrefSize(305,30);
// Populate the lists DVD[] theList = model.getDVDList(); String[] titles = new String[theList.length]; Integer[] years = new Integer[theList.length]; Integer[] lengths = new Integer[theList.length]; for (int i=0; i // Add all the components to the Pane aPane.getChildren().addAll(label1, label2, label3, tList, yList, lList, buttonPane); aPane.setPrefSize(348, 228); primaryStage.setTitle("My DVD Collection"); primaryStage.setResizable(false); primaryStage.setScene(new Scene(aPane)); primaryStage.show(); } public static void main(String[] args) { launch(args); } } public class DVD implements Comparable { private String title; private int year; private int duration; public DVD () { this ("",0,0); } public DVD (String newTitle, int y, int minutes) { title = newTitle; year = y; duration = minutes; } public int compareTo(Object obj) { if (obj instanceof DVD) { DVD aDVD = (DVD)obj; return title.compareTo(aDVD.title); } return 0; } public String getTitle() { return title; } public int getDuration() { return duration; } public int getYear() { return year; } public void setTitle(String t) { title = t; } public void setDuration(int d) { duration = d; } public void setYear(int y) { year = y; } public String toString() { return ("DVD (" + year + "): \"" + title + "\" with length: " + duration + " minutes"); } } public class DVDCollection { public static final int MAX_DVDS = 100; private DVD[] dvds; private int dvdCount; private int selectedDVD; public DVDCollection() { dvds = new DVD[MAX_DVDS]; selectedDVD = -1; } public void setSelectedDVD(int i) { selectedDVD = i; } public DVD[] getDvds() { return dvds; } public DVD[] getDVDList() { DVD[] list = new DVD[dvdCount]; for (int i=0; i return list; } public int getDvdCount() { return dvdCount; } public String toString() { return ("DVD Collection of size " + dvdCount); } public void add(DVD aDvd) { if (dvdCount public static DVDCollection example1() { DVDCollection c = new DVDCollection(); c.add(new DVD("If I Was a Student", 2007, 65)); c.add(new DVD("Don't Eat Your Pencil !", 1984, 112)); c.add(new DVD("The Exam", 2001, 180)); c.add(new DVD("Tutorial Thoughts", 2003, 128)); c.add(new DVD("Fried Monitors", 1999, 94)); return c; } public static DVDCollection example2() { DVDCollection c = new DVDCollection(); c.add(new DVD("Titanic",1997,194)); c.add(new DVD("Star Wars",1977,121)); c.add(new DVD("E.T. - The Extraterrestrial",1982,115)); c.add(new DVD("Spider Man",2002,121)); c.add(new DVD("Jurassic Park",1993,127)); c.add(new DVD("Finding Nemo",2003,100)); c.add(new DVD("The Lion King",1994,89)); c.add(new DVD("Up",2009,96)); c.add(new DVD("The Incredibles",2004,115)); c.add(new DVD("Monsters Inc.",2001,92)); c.add(new DVD("Cars",2006,117)); c.add(new DVD("Beverly Hills Cop",1984,105)); c.add(new DVD("Home Alone",1990,103)); c.add(new DVD("Jaws",1975,124)); c.add(new DVD("Men in Black",1997,98)); c.add(new DVD("Independence Day",1996,145)); c.add(new DVD("National Treasure: Book of Secrets",2007,124)); c.add(new DVD("Aladdin",1992,90)); c.add(new DVD("Twister",1996,113)); c.add(new DVD("Iron Man",2008,126)); c.add(new DVD("Alice in Wonderland",2010,108)); c.add(new DVD("Transformers",2007,144)); return c; } public static DVDCollection example3() { DVDCollection c = new DVDCollection(); c.add(new DVD("Avatar",2009,162)); c.add(new DVD("The Avengers",2012,143)); c.add(new DVD("Titanic",1997,194)); c.add(new DVD("The Dark Knight",2008,152)); c.add(new DVD("Star Wars",1977,121)); c.add(new DVD("Shrek 2",2004,93)); c.add(new DVD("E.T. - The Extraterrestrial",1982,115)); c.add(new DVD("Star Wars - Episode I",1999,136)); c.add(new DVD("Pirates of the Caribbean: Dead Man's Chest",2006,151)); c.add(new DVD("Toy Story 3",2010,103)); c.add(new DVD("Spider Man",2002,121)); c.add(new DVD("Transformers: Revenge of the Fallen",2009,150)); c.add(new DVD("Star Wars - Episode III",2005,140)); c.add(new DVD("Spider Man 2",2004,127)); c.add(new DVD("Jurassic Park",1993,127)); c.add(new DVD("Transformers: Dark of the Moon",2011,154)); c.add(new DVD("Finding Nemo",2003,100)); c.add(new DVD("Spider Man 3",2007,139)); c.add(new DVD("Forrest Gump",1994,142)); c.add(new DVD("The Lion King",1994,89)); c.add(new DVD("Shrek the Third",2007,93)); c.add(new DVD("The Sixth Sense",1999,107)); c.add(new DVD("Up",2009,96)); c.add(new DVD("I am Legend",2007,101)); c.add(new DVD("Shrek",2001,90)); c.add(new DVD("The Incredibles",2004,115)); c.add(new DVD("Monsters Inc.",2001,92)); c.add(new DVD("Brave",2012,100)); c.add(new DVD("Toy Story 2",1999,92)); c.add(new DVD("Cars",2006,117)); c.add(new DVD("Signs",2002,106)); c.add(new DVD("Hancock",2008,92)); c.add(new DVD("Rush Hour 2",2001,90)); c.add(new DVD("Meet the Fockers",2004,115)); c.add(new DVD("The Hangover",2009,100)); c.add(new DVD("My Big Fat Greek Wedding",2002,95)); c.add(new DVD("Beverly Hills Cop",1984,105)); c.add(new DVD("Mrs. Doubtfire",1993,125)); c.add(new DVD("The Hangover Part II",2011,102)); c.add(new DVD("The Matrix Reloaded",2003,138)); c.add(new DVD("Home Alone",1990,103)); c.add(new DVD("Jaws",1975,124)); c.add(new DVD("The Blind Side",2009,129)); c.add(new DVD("Men in Black",1997,98)); c.add(new DVD("X-Men: The Last Stand",2006,104)); c.add(new DVD("The Bourne Ultimatum",2007,115)); c.add(new DVD("WALL-E",2008,98)); c.add(new DVD("Inception",2010,148)); c.add(new DVD("Independence Day",1996,145)); c.add(new DVD("Pirates of the Caribbean: The Curse of the Black Pearl",2003,143)); c.add(new DVD("The Chronicles of Narnia",2005,143)); c.add(new DVD("War of the Worlds",2005,116)); c.add(new DVD("National Treasure: Book of Secrets",2007,124)); c.add(new DVD("Aladdin",1992,90)); c.add(new DVD("How to Train Your Dragon",2010,98)); c.add(new DVD("Shrek Forever After",2010,93)); c.add(new DVD("Twister",1996,113)); c.add(new DVD("Star Wars - Episode VI",1983,134)); c.add(new DVD("Iron Man",2008,126)); c.add(new DVD("Alice in Wonderland",2010,108)); c.add(new DVD("Transformers",2007,144)); c.add(new DVD("Star Wars - Episode II",2002,142)); return c; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started