別のクラスにあるテーブルに行を追加するのが難しいです。
クラス構造は次のとおりです。
破線の矢印は、私がなんとか持っていない望ましい関係です
クラスにAddPanel
は、フィールドと追加ボタンがあります。
addButton をクリックすると、最初に Product のインスタンス (Logic Package にあるクラス) を作成します。次に、テーブルに行を追加する必要があります (TableModel.AddRow
メソッドを使用)。
以下は GUI の外観です (フォーカスされたタブは ですAddPannel
)。
さまざまなアプローチを試みましたが、どれも成功しませんでした。
私の最後の試みは、Table
クラスで次のメソッドを作成することでした:
public void AddRow(Product p) {
tbmStock.addRow(new Object[] { p.getExternalId(), p.getName(),
p.getAmount(), p.getPriceForMe(), p.getPriceForCustomer() });
}
さらに、AddPanel
クラスでは、次のメソッドを追加しようとしました。
private void AddButtonAction() {
btnAddProduct.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Product p = new Product(txtName.getText(), txtExternalID
.getText(), Integer.parseInt(txtAmount.getText()),
Double.parseDouble(txtPriceForMe.getText()),
Double.parseDouble(txtPriceForCustomer.getText()),
Integer.parseInt(txtFromYear.getText()), Integer
.parseInt(txtToYear.getText()), Integer
.parseInt(txtSupplier.getText()), Integer
.parseInt(txtCarType.getText()));
AddRow(p); //This call doesn't compiles
}
catch (Exception e1){
JOptionPane.showMessageDialog(null,"Error");
}
}
});
}
助言がありますか ?(実際、私の構造が良いかどうかさえわかりません:S)