Как я могу использовать два TableView в одном классе контроллера Java - PullRequest
0 голосов
/ 11 декабря 2018

Я хочу использовать 2 таблицы с разными классами в одном контроллере Java.Как мне это сделать:

public class TransactionHistoryController implements Initializable {

@FXML
private  Label acc_no;
@FXML
private  Label amt;
@FXML
private TableView<History> withdraw_table;
@FXML
private TableColumn<History, String> accountno;
@FXML
private TableColumn<History, String> amount;
@FXML
private TableColumn<History, String> remainingamount;
@FXML
private TableColumn<History, String> dates;
@FXML
private TableColumn<History, String> times;

@FXML
private TableView<Deposit> deposit_table;
@FXML
private TableColumn<Deposit, String> deposit_accountno;
@FXML
private TableColumn<Deposit, String> deposit_amount;
@FXML
private TableColumn<Deposit, String> deposit_newamount;
@FXML
private TableColumn<Deposit, String> deposit_dates;
@FXML
private TableColumn<Deposit, String> deposit_times;

public static String ac = DashboardContoller.a1;

публичный недействительный депозит () {

        deposit_accountno.setCellValueFactory(new PropertyValueFactory<Deposit,String>("deposit_acc"));
        deposit_amount.setCellValueFactory(new PropertyValueFactory<Deposit,String>("deposit_amt"));
        deposit_newamount.setCellValueFactory(new PropertyValueFactory<Deposit,String>("new_amt"));
        deposit_dates.setCellValueFactory(new PropertyValueFactory<Deposit,String>("deposit_date"));
        deposit_times.setCellValueFactory(new PropertyValueFactory<Deposit,String>("deposit_time"));

    Connection con=null;
    PreparedStatement ps=null;
    ResultSet rs=null;
    ObservableList<Deposit> list = FXCollections.observableArrayList();

     try
    {
        Class.forName("com.mysql.jdbc.Driver");
        con=DriverManager.getConnection("jdbc:mysql://localhost:3306/udemy","root","");

        ps=con.prepareStatement("SELECT * FROM  deposit WHERE AccountNo=?");

        ps.setString(1, ac);


         rs=ps.executeQuery();
        while(rs.next())
        {

             list.addAll(new Deposit(rs.getString("AccountNo"), rs.getString("DepositAmount"), rs.getString("NewAmount"), rs.getString("Date"), rs.getString("Time")));
         JOptionPane.showMessageDialog(null,list);
        }




    }catch(Exception e)
    {
        JOptionPane.showMessageDialog(null,e);
    }

     deposit_table.setItems(list);

}

публичный недействительный вывод () {

accountno.setCellValueFactory (new PropertyValueFactory ("account_number"));amount.setCellValueFactory (new PropertyValueFactory ("withDrawAmount"));оставшиесяamount.setCellValueFactory (new PropertyValueFactory ("ОстатокAmount"));date.setCellValueFactory (new PropertyValueFactory ("date"));times.setCellValueFactory (new PropertyValueFactory ("time"));

    Connection con=null;
    PreparedStatement ps=null;
    ResultSet rs=null;
    ObservableList<History> list = FXCollections.observableArrayList();

    try
    {
        Class.forName("com.mysql.jdbc.Driver");
        con=DriverManager.getConnection("jdbc:mysql://localhost:3306/udemy","root","");
        ps=con.prepareStatement("SELECT * FROM  withdraw WHERE AccountNo=?");

        ps.setString(1, ac);


         rs=ps.executeQuery();
        while(rs.next())
        {

             list.addAll(new History(rs.getString("AccountNo"), rs.getString("WithdrawAmount"), rs.getString("RemainingAmount"), rs.getString("Date"), rs.getString("Time")));
         }


    }catch(Exception e)
    {
        JOptionPane.showMessageDialog(null,e);
    }

    withdraw_table.setItems(list);

}

@Override
public void initialize(URL url, ResourceBundle rb) {

    deposit();
    withdraw();

} 

}

Ниже представлен класс истории

public class History {

private String account_number;
 private String withDrawAmount;
 private String remainingAmount;
 private String date;
 private String time;

public History(String account_number, String withDrawAmount, String remainingAmount, String date, String time) {
    this.account_number = account_number;
    this.withDrawAmount = withDrawAmount;
    this.remainingAmount = remainingAmount;
    this.date = date;
    this.time = time;
}

public String getAccount_number() {
    return account_number;
}

public String getWithDrawAmount() {
    return withDrawAmount;
}

public String getRemainingAmount() {
    return remainingAmount;
}

public String getDate() {
    return date;
}

public String getTime() {
    return time;
}

}

Это класс депозита:

class Deposit{

private String name;
private String amount;
private String newAmount;
private String date;
private String time;

public Deposit(String name, String amount, String newAmount, String date, String time) {
    this.name = name;
    this.amount = amount;
    this.newAmount = newAmount;
    this.date = date;
    this.time = time;
}

public String getName() {
    return name;
}

public String getAmount() {
    return amount;
}

public String getNewAmount() {
    return newAmount;
}

public String getDate() {
    return date;
}

public String getTime() {
    return time;
}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...