i want to create JFrame with multiple panel each panel displaying some information from database (say product_id and description ) and each frame have a button(add to cart) which will add the information from that panel to cart table in my database how will i implement this?
我想要创建一个包含多个面板的JFrame,每个面板都显示来自数据库的一些信息(比如product_id和description),每个框架都有一个按钮(添加到购物车),它将从该面板中添加信息到cart表,在我的数据库中,我将如何实现它?
2 个解决方案
#1
2
I would try to simply things by using a JTable to display such data, with each column displaying a database field. I'd add an extra column, say a Boolean column that displays as a check box, and then assess the state of that column when needing to decide which to add to a cart.
我尝试使用JTable来显示这些数据,每个列都显示一个数据库字段。我将添加一个额外的列,比如一个作为复选框显示的布尔列,然后在需要决定向购物车添加哪个列时评估该列的状态。
Edit You ask:
编辑你问:
how will i know how much quantity of that product is selected,
我怎么知道选了多少产品,
Then add a quantity field as well, perhaps one that uses a JSpinner as its editor.
然后添加一个quantity字段,可能是使用JSpinner作为编辑器的字段。
and also i am thinking to add image of that product also can i do it in Jtables
我也想添加那个产品的图像我也可以在Jtables中做。
Absolutely. It knows how to display ImageIcons for instance. Please have a look at my answer to another question for an example.
绝对的。例如,它知道如何显示图像图标。请看我对另一个问题的回答。
#2
0
You should create a JPanel (called PanelButton) which contents [Add to cart] button.
您应该创建一个包含[添加到购物车]按钮的JPanel(称为PanelButton)。
In other JPanels, you add PanelButton.
在其他jpanel中,添加PanelButton。
So, by this way, you can reuse your button without implement a lot of [Add to cart] button for each panel.
因此,通过这种方式,您可以重用按钮,而不必为每个面板实现大量的[Add to cart]按钮。
#1
2
I would try to simply things by using a JTable to display such data, with each column displaying a database field. I'd add an extra column, say a Boolean column that displays as a check box, and then assess the state of that column when needing to decide which to add to a cart.
我尝试使用JTable来显示这些数据,每个列都显示一个数据库字段。我将添加一个额外的列,比如一个作为复选框显示的布尔列,然后在需要决定向购物车添加哪个列时评估该列的状态。
Edit You ask:
编辑你问:
how will i know how much quantity of that product is selected,
我怎么知道选了多少产品,
Then add a quantity field as well, perhaps one that uses a JSpinner as its editor.
然后添加一个quantity字段,可能是使用JSpinner作为编辑器的字段。
and also i am thinking to add image of that product also can i do it in Jtables
我也想添加那个产品的图像我也可以在Jtables中做。
Absolutely. It knows how to display ImageIcons for instance. Please have a look at my answer to another question for an example.
绝对的。例如,它知道如何显示图像图标。请看我对另一个问题的回答。
#2
0
You should create a JPanel (called PanelButton) which contents [Add to cart] button.
您应该创建一个包含[添加到购物车]按钮的JPanel(称为PanelButton)。
In other JPanels, you add PanelButton.
在其他jpanel中,添加PanelButton。
So, by this way, you can reuse your button without implement a lot of [Add to cart] button for each panel.
因此,通过这种方式,您可以重用按钮,而不必为每个面板实现大量的[Add to cart]按钮。