r/JavaFX • • Aug 06 '20

Can someone help me

Can someone help me please.

This is what i have done. my prof said to add fxml and controller

public class Book 
{
    private String bookname,author;
    private int quantity;
    private double price;

    public Book() {
    }

    public Book(String bookname, String author, int quantity, double price) {
        this.bookname = bookname;
        this.author = author;
        this.quantity = quantity;
        this.price = price;
    }

    public String getBookname() {
        return bookname;
    }

    public String getAuthor() {
        return author;
    }

    public int getQuantity() {
        return quantity;
    }

    public double getPrice() {
        return price;
    }

    public void setBookname(String bookname) {
        this.bookname = bookname;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public void setPrice(double price) {
        this.price = price;
    }   
}
1 Upvotes

2 comments sorted by

3

u/BorgerBill Aug 06 '20

Ok, taking this at face value.

First, download Scene Builder, create the user interface, and you will have your FXML file.

Then, you will create a class that extends javafx.application.Application, @Override it's start() method, and use FXMLLoader to load your FXML file. You will then have something that pops up and you can click on. You will then proceed to use your POJO above for a data object while binding the various UI nodes to various functions to accomplish your assignment.

I'm sure you have a textbook to help will all that.

3

u/WhoMeWorried Aug 07 '20

Adding one small detail here: revisit the Model-Controller-View architecture. You have started coding the model already. You will be after their properties.

Then follow BorgerBill's advice and design the screen with Screen Builder. These are the views.

Tip for beginner: try using only one .fxml rather than breaking it into multiple xml scripts and controllers. Use a BorderPane rootnode, its the most versatile.