2013-04-20 111 views
0

我試圖添加一行記錄到我現有的MS數據庫。 基本上這些記錄將被輸入到GUI中,然後在用戶單擊提交時添加到數據庫中。如何通過Java將記錄添加到MS Access

我創建了GUI,使用3個JLabel,3個JTextfield和1個JButton。 用戶需要輸入名稱,數量和價格,然後點擊提交按鈕。

JLabel newproductname = new JLabel("Enter Product Name"); 
JTextField npn = new JTextField(7); 
JLabel newproductprice = new JLabel("Enter Product Price"); 
JTextField npp = new JTextField(7); 
JLabel newproductstock = new JLabel("Enter Product Stock"); 
JTextField nps = new JTextField(7); 
JButton addnewitem = new JButton("Add New Item"); 

這是我用來創建GUI,很顯然,我已經加入這一切到面板下方

我是新來的Java,所以我會很感激的東西任何人術語可以理解, 謝謝!

回答

0

爲此使用ActionListioner事件。當你點擊按鈕時,會觸發一個事件,該事件將通過ActionListioner接口(event handling)處理,其中有一個方法actionPerformed(ActionEvent),您需要實施此方法來處理您的事件。 I-E

class GUI implements ActionListener{ 
    JLabel newproductname = new JLabel("Enter Product Name"); 
JTextField npn = new JTextField(7); 
JLabel newproductprice = new JLabel("Enter Product Price"); 
JTextField npp = new JTextField(7); 
JLabel newproductstock = new JLabel("Enter Product Stock"); 
JTextField nps = new JTextField(7); 
JButton addnewitem = new JButton("Add New Item"); 

void storeMethod(String npn, string npp, string nps){ 
    // some implementation 
} 

public void actionPerformed(ActionEvent ae){ 
    storeMethod(npn.getText(), npp.getText(), nps.getText()); 
} 

void drawForm(){ 
// some implementation 
addnewitem.addActionListener(this); 
} 

main(){ 
new GUI().drawForm(); 
} 

}

這裏是一個link這將有助於你在MS-評估連接。 從這裏您可以找到源代碼link2

+0

如果我發佈我的整個代碼會幫助嗎? – Mark 2013-04-20 11:59:35

+0

請做,我知道如何編輯記錄,例如更改項目的名稱。但我需要知道如何輸入項目到一個新的行 – Mark 2013-04-20 12:19:29

+0

再次檢查我的帖子。 – 2013-04-20 12:33:10

0

要使用Java在MS Access中添加記錄,您需要使用JDBC來插入記錄。 Refer Here

相關問題