如何通过Java将记录添加到MS Access
问题描述:
我试图添加一行记录到我现有的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,所以我会很感激的东西任何人术语可以理解, 谢谢!
答
为此使用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();
}
}
如果我发布我的整个代码会帮助吗? – Mark 2013-04-20 11:59:35
请做,我知道如何编辑记录,例如更改项目的名称。但我需要知道如何输入项目到一个新的行 – Mark 2013-04-20 12:19:29
再次检查我的帖子。 – 2013-04-20 12:33:10