2016-11-27 91 views
1

如果我有一個準備好語句的類,當用戶按下按鈕時如何調用它們。如何在另一個類中調用Java類的變量

class updateeButtonHandler implements ActionListener 
{ 
    public void actionPerformed(ActionEvent e) 
    { 
     name = displayName.getText(); 
     price = bookPrice.getText(); 
     Queries update = new Queries();??????????????????? 
    } 
} 

在不同類

public int update(String price, String name) throws SQLException { 
     ps2.setString(1, name); 
     ps2.setString(2, price); 
     System.out.print("Update - "); 
     return ps2.executeUpdate(); 
    } 

回答

0

預處理語句創建一個對象,並調用與參數的更新方法如下所示:

public void actionPerformed(ActionEvent e) { 
     name = displayName.getText(); 
     price = bookPrice.getText(); 
     Queries update = new Queries(); 
     update.update(price, name);//invoke the method using the object 
} 
+0

除了可以實例化類在construtor或通而不是在方法內部創建更多的面向對象。 –

+0

你會怎麼做?如何顯示返回價值。謝謝 – joe

+0

請任何意見 – joe

相關問題