1

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322

2 Answers2

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.


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.

and also i am thinking to add image of that product also can i do it in Jtables

Absolutely. It knows how to display ImageIcons for instance. Please have a look at my answer to another question for an example.

Community
  • 1
  • 1
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • how will i know how much quantity of that product is selected and also i am thinking to add image of that product also can i do it in Jtables – user3430383 Apr 06 '14 at 18:21
  • how can i add checkbox in a Jtable? – user3430383 Apr 06 '14 at 18:25
  • @user3430383: if using a DefaultTableModel, make sure that the column of interest, the one that is to display a check box is of Boolean type. Then override the model's `getColumnClass(int columnIndex)` to return `Boolean.class`. – Hovercraft Full Of Eels Apr 06 '14 at 18:26
0

You should create a JPanel (called PanelButton) which contents [Add to cart] button.

In other JPanels, you add PanelButton.

So, by this way, you can reuse your button without implement a lot of [Add to cart] button for each panel.

tana
  • 585
  • 1
  • 5
  • 16