0

我试图将一行记录添加到我已经存在的 MS 数据库中。基本上,这些记录将被输入到 GUI 中,然后在用户单击提交时添加到数据库中。

我使用 3 个 JLabel、3 个 JTextfield 和 1 个 JButton 创建了 GUI。用户需要输入名称、数量和价格,然后单击提交按钮。

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 新手,所以我很欣赏任何人都能理解的术语,谢谢!

4

2 回答 2

0

要使用 Java 在 MS Access 中添加记录,您需要使用 JDBC 插入记录。 参考这里

于 2013-04-20T12:15:29.007 回答
0

为此使用 ActionListioner 事件。当您单击按钮时,将触发一个事件,该事件将通过 ActionListioner 接口(事件处理)处理,它有一个方法 actionPerformed(ActionEvent),您需要提供此方法的实现来处理您的事件。IE

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();
}

}

这是一个链接,可帮助您连接 MS-Assess。从这里你会找到源代码link2

于 2013-04-20T11:49:38.227 回答