I need Help In Java FX, I want the interface exactly like the following: The fir
ID: 3889962 • Letter: I
Question
I need Help In Java FX, I want the interface exactly like the following:
The first image shows the initial image produced by the program. It has labels for Author, Title and Pages, and under each label is a TextField accepting user input for the associated information. It also has a button for Make New Book. The user can fill in each required data in each TextField, and when the button is pushed the program creates a Book object and adds it to a DataSetBook.
Below the widgets described above is a TextArea displaying the toString value of the DataSetBook object. As Make New Book is pushed and a new Book added to the DataSetBook, the TextArea is updated.
The second image shows that data has been entered for a book, but the button not yet pushed.
In the third image, the button has been pushed and the first book added to the DataSetBook.
The last image shows a second book has been entered, the button pushed, and the TextArea updated.
Your mission for this program is to "go and do better" than this program. A Book class ,use the DataSetBook . Choose appropriate Layout Panes to improve on this GUI's appearance. You may wish to tweak the toString methods of Book and DataSetBook. You should use a simple, named inner class as the event handler for the button.
public class Book {
private String author;
private String title;
private int pages;
public Book(String auth, String titl, int pag) {
author = auth;
title = titl;
pages = pag;
}
public int getPages() {
return pages;
}
@Override
public String toString() {
return "Book [author=" + author + ", title=" + title + ", pages=" + pages + "] ";
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Book other = (Book) obj;
if (author == null) {
if (other.author != null)
return false;
} else if (!author.equals(other.author))
return false;
if (pages != other.pages)
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}}
---------------------
DataSetBook
import java.util.ArrayList;
/**
* A simple store for Book objects.
*/
public class DataSetBook extends ArrayList<Book>{
/**
* Default constructor
*/
public DataSetBook() {
}
public boolean add(Book objToAdd) {
return super.add(objToAdd);
}
/**
* The number of Books currently in the store
*
* @return number of Book objects
*/
public int size() {
return super.size();
}
/**
* Determine the Book with the fewest pages
*
* @return null if the store is empty. The book with the fewest pages
* otherwise. If more than one book has the fewest number of pages,
* the first one is returned.
*/
public Book getMin() {
if (super.isEmpty()) {
return null;
}
Book mEle = super.get(0);
for (int i = 1; i < super.size(); i++) {
if (mEle.getPages() > (super.get(i).getPages())) {
mEle = super.get(i);
}
}
return mEle;
}
/* Determine the Book with the most pages
public Book getMax() {
if (super.isEmpty()) {
return null;
}
Book mEle = super.get(0);
for (int i = 1; i < super.size(); i++) {
if (mEle.getPages() < (super.get(i).getPages())) {
mEle = super.get(i);
}}
return mEle;
}
@Override
public String toString() {
return "DataSetBook size()=" + size() + " getMin()=" + getMin() + " getMax()=" + getMax()
+ " Books= " + super.toString() ;
}}
Author Title Make New Book DataSetBook []Explanation / Answer
WORK DONE
public class Book {
private String author;
private String title;
private int pages;
public Book(String auth, String titl, int pag) {
author = auth;
title = titl;
pages = pag;
}
public int getPages() {
return pages;
}
@Override
public String toString() {
return "Book [author=" + author + ", title=" + title + ", pages=" + pages + "] ";
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Book other = (Book) obj;
if (author == null) {
if (other.author != null)
return false;
} else if (!author.equals(other.author))
return false;
if (pages != other.pages)
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}}
---------------------
DataSetBook
import java.util.ArrayList;
/**
* A simple store for Book objects.
*/
public class DataSetBook extends ArrayList<Book>{
/**
* Default constructor
*/
public DataSetBook() {
}
public boolean add(Book objToAdd) {
return super.add(objToAdd);
}
/**
* The number of Books currently in the store
*
* @return number of Book objects
*/
public int size() {
return super.size();
}
/**
* Determine the Book with the fewest pages
*
* @return null if the store is empty. The book with the fewest pages
* otherwise. If more than one book has the fewest number of pages,
* the first one is returned.
*/
public Book getMin() {
if (super.isEmpty()) {
return null;
}
Book mEle = super.get(0);
for (int i = 1; i < super.size(); i++) {
if (mEle.getPages() > (super.get(i).getPages())) {
mEle = super.get(i);
}
}
return mEle;
}
/* Determine the Book with the most pages
public Book getMax() {
if (super.isEmpty()) {
return null;
}
Book mEle = super.get(0);
for (int i = 1; i < super.size(); i++) {
if (mEle.getPages() < (super.get(i).getPages())) {
mEle = super.get(i);
}}
return mEle;
}
@Override
public String toString() {
return "DataSetBook size()=" + size() + " getMin()=" + getMin() + " getMax()=" + getMax()
+ " Books= " + super.toString() ;
}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.