Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 {

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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 tList; private ListView yList, lList;

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(); tList.relocate(10, 40); tList.setPrefSize(200,150);

yList = new ListView(); yList.relocate(220, 40); yList.setPrefSize(60,150);

lList = new ListView(); lList.relocate(290, 40); lList.setPrefSize(60,150);

// 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; } }

1Run the BorderPaneExampleApp code. You should see the window as shown below: My DVD Collection Length 65 112 180 128 94 Title Year If I Was a Student Don't Eat Your Pencil The Exam Tutorial Thoughts Fried Monitors 2007 1984 2001 2003 1999 Add Delete Stats The code creates a non-resizable window. We will modify this code to use a BorderPane so that the window will resize nicely. Begin by removing this line of code near the end of the start) method primaryStage.setResizable (false) The window will now resize, but the components do not grow, nor do they change locations. Re-write the code so that the window has three panes which are all added to a BorderPane at the top, center and bottom as shown below: 1Run the BorderPaneExampleApp code. You should see the window as shown below: My DVD Collection Length 65 112 180 128 94 Title Year If I Was a Student Don't Eat Your Pencil The Exam Tutorial Thoughts Fried Monitors 2007 1984 2001 2003 1999 Add Delete Stats The code creates a non-resizable window. We will modify this code to use a BorderPane so that the window will resize nicely. Begin by removing this line of code near the end of the start) method primaryStage.setResizable (false) The window will now resize, but the components do not grow, nor do they change locations. Re-write the code so that the window has three panes which are all added to a BorderPane at the top, center and bottom as shown below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

Circle the eight isoprene units in b-carotene.

Answered: 1 week ago