Я пытался скопировать формат из другого файла, который делает очень похожую вещь, но когда я запускаю свое приложение, единственное, что работает, это кнопка очистки и обновления.Мне еще предстоит запрограммировать кнопку открытия, потому что я не уверен, как это должно работать.В разделе отображения обновлений предполагается сложить все суммы, которые были сохранены в текстовом файле, но не уверены, как это сделать
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
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;
import javafx.scene.layout.AnchorPane;
import javafx.scene.input.MouseEvent;
public class FXMLDocumentController implements Initializable
{
DonorListModel donorList;
MissionaryListModule missionaryList;
@FXML
private TextField firstField;
@FXML
private TextField lastField;
@FXML
private TextField addressField;
@FXML
private TextField donorAmountField;
@FXML
private TextField stateField;
@FXML
private TextField zipField;
@FXML
private TableView<Donor> donorTable;
@FXML
private AnchorPane addressTable;
@FXML
private TableColumn<Donor, String> donorFirstField;
@FXML
private TableColumn<Donor, String> donorLastField;
@FXML
private TextField dateField;
@FXML
private TableColumn<Donor, String> donorAddressField;
@FXML
private TableColumn<Donor, String> donorStateField;
@FXML
private TableColumn<Donor, String> donorZipField;
@FXML
private TextField missonFirstField;
@FXML
private TextField missionLastField;
@FXML
private TextField goalField;
@FXML
private TextField missionAddressfield;
@FXML
private TextField totalField;
@FXML
private TextField phoneField;
@FXML
private TextField missionStateField;
@FXML
private TextField missionZipField;
@FXML
private Button buttonClear;
@FXML
private Button buttonFind;
@FXML
private Button buttonUpdate;
@FXML
private Button buttonDelete;
@FXML
private Button buttonOpen;
@FXML
private TableColumn<Donor, String> donorDateField;
@FXML
private TableColumn<Donor, Float> amountField;
/**
* Clears the text fields and updates the display
*
* @param event
*/
@FXML
void handleButtonClear(ActionEvent event)
{
clearFields();
updateDisplay();
}
@FXML
void handleButtonDelete(ActionEvent event)
{
Donor i = new Donor(firstField.getText(),"", "", stateField.getText(),
zipField.getText(), dateField.getText(), 0);
donorList.removeItem(i);
updateDisplay();
clearFields();
}
@FXML
void handleButtonFind(ActionEvent event)
{
Donor i = new Donor(firstField.getText(), lastField.getText(),
"", stateField.getText(), zipField.getText(), dateField.getText(),
Float.parseFloat(amountField.getText()));
List<Donor> l = donorList.findItem(i);
donorTable.getItems().setAll(l);
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
donorList = new DonorListModel();
donorList.loadList();
donorFirstField.setCellValueFactory(new PropertyValueFactory<>
("firstName"));
donorLastField.setCellValueFactory(new PropertyValueFactory<>
("lastName"));
donorAddressField.setCellValueFactory(new PropertyValueFactory<>
("Address"));
donorStateField.setCellValueFactory(new PropertyValueFactory<>
("State"));
donorZipField.setCellValueFactory(new PropertyValueFactory<>("zip"));
donorDateField.setCellValueFactory(new PropertyValueFactory<>("Date"));
amountField.setCellValueFactory(new PropertyValueFactory<>("amount"));
updateDisplay();
}
@FXML
void handleButtonOpen(ActionEvent event)
{
}
/**
* Add or modify shopping list item when update button is pressed
*
* @param event
*/
@FXML
void handleButtonUpdate(ActionEvent event)
{
if (firstField.getText().matches("[a-zA-Z]+") &&
lastField.getText().matches("[a-zA-Z]+"))
{
//checks that name is only alphabetic
Donor i = new Donor(firstField.getText(), lastField.getText(),
addressField.getText(), stateField.getText(),
zipField.getText(), dateField.getText(),
Float.parseFloat(donorAmountField.getText()));
donorList.addItem(i);
updateDisplay();
clearFields();
firstField.requestFocus();
updateDisplay();
}
}
@FXML
void handleTableClick(MouseEvent event) {
Donor i = donorTable.getSelectionModel().getSelectedItem();
if (i != null) {
firstField.setText(i.getFirstName());
lastField.setText(String.valueOf(i.getLastName()));
addressField.setText(String.valueOf(i.getAddress()));
zipField.setText(String.valueOf(i.getZip()));
stateField.setText(String.valueOf(i.getState()));
dateField.setText(String.valueOf(i.getDate()));
donorAmountField.setText(String.valueOf(i.getAmount()));
}
}
/**
* Updates the display including the total item count and cost
*/
private void updateDisplay()
{
float cost = 0;
int itemCount = 0;
donorTable.getItems().setAll(donorList.getDonor());
List<Donor> items = donorList.getDonor();
for (Donor item : items)
{
System.out.println("Placeholder");
}
}
/**
* Clears the text fields
*/
private void clearFields()
{
firstField.setText("");
lastField.setText((""));
addressField.setText((""));
stateField.setText("");
zipField.setText("");
donorAmountField.setText("");
dateField.setText("");
missonFirstField.setText("");
missionLastField.setText((""));
missionAddressfield.setText((""));
missionStateField.setText("");
missionZipField.setText("");
phoneField.setText("");
}
}