Created
May 22, 2018 16:08
-
-
Save ityulkanov/35c1fb20b16925b57fa9562368c33417 to your computer and use it in GitHub Desktop.
java controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.collections.FXCollections; | |
import javafx.collections.ObservableList; | |
import javafx.fxml.FXML; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.TableColumn; | |
import javafx.scene.control.TableView; | |
import javafx.scene.control.TextField; | |
import javafx.scene.control.cell.PropertyValueFactory; | |
public class Controller { | |
@FXML | |
private TextField tfId; | |
@FXML | |
private TextField tfTitle; | |
@FXML | |
private TextField tfAuthor; | |
@FXML | |
private TextField tfYear; | |
@FXML | |
private Button btnAdd; | |
@FXML | |
private TableView<Book> tvData; | |
@FXML | |
private TableColumn<Book, Integer> tcId; | |
@FXML | |
private TableColumn<Book, String> tcTitle; | |
@FXML | |
private TableColumn<Book, String> tcAuthor; | |
@FXML | |
private TableColumn<Book, Integer> tcYear; | |
@FXML | |
private ObservableList<Book> bookData = | |
FXCollections.observableArrayList(); | |
@FXML | |
public void initialize() { | |
tcId.setCellValueFactory(new PropertyValueFactory<Book, Integer>("id")); | |
tcTitle.setCellValueFactory(new PropertyValueFactory<Book, String>("title")); | |
tcAuthor.setCellValueFactory(new PropertyValueFactory<Book, String>("author")); | |
tcYear.setCellValueFactory(new PropertyValueFactory<Book, Integer>("year")); | |
tvData.setItems(bookData); | |
} | |
@FXML | |
public void onClickAdd() { | |
bookData.add(new Book(Integer.parseInt(tfId.getText()), | |
tfTitle.getText(), | |
tfAuthor.getText(), | |
Integer.parseInt(tfYear.getText()))); | |
System.out.println("Data added"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment