1

I am trying to make an ordering system for a coffee shop and I I am trying to work out how to allow the staff member to order multiple units of the same item (eg. 3 Mocha Lattes).

The only thing I have done similar to this was a pizza ordering system but I only needed to order 1 of each thing so I used radio buttons and checkboxes.

Could I use a JComboBox for this? I can't see how it would work without creating a new combo box for each item.

There has to be a much more efficient way of doing this!

Thanks for your help.

public CoffeeShop(){

    pane.setLayout(new GridLayout(3,1));

    tabbedPane = new JTabbedPane();

    pnlName = new JPanel();
    pnlName.setLayout(new GridLayout(4,1));
    pnlTableNum = new JPanel();
    pnlTableNum.setLayout(new FlowLayout(FlowLayout.LEFT));
    pnlOrdNum = new JPanel();
    pnlOrdNum.setLayout(new FlowLayout(FlowLayout.LEFT));
    pnlNameDetails = new JPanel();
    pnlNameDetails.setLayout(new FlowLayout(FlowLayout.LEFT));
    lblHeader = new JLabel("The Bean Scene Coffee Studio");
    lblName = new JLabel("Customer Name: ");
    txtName = new JTextField(15);
    lblOrdNum = new JLabel("Order Number:     ");
    lblOrderNumber = new JLabel("");
    lblTableNum = new JLabel("Table Number:     ");
    txtTableNum = new JTextField(15);

    pnlNameDetails.add(lblName);
    pnlNameDetails.add(txtName);
    pnlTableNum.add(lblTableNum);
    pnlTableNum.add(txtTableNum);
    pnlOrdNum.add(lblOrdNum);
    pnlOrdNum.add(lblOrderNumber);

    pnlName.add(lblHeader);
    pnlName.add(pnlNameDetails);
    pnlName.add(pnlTableNum);
    pnlName.add(pnlOrdNum);

    pane.add(pnlName);

    pnlHotDrink = new JPanel();
    pnlHotDrink.setLayout(new GridLayout(3,3));
    chkLatte = new JCheckBox("Latte");
    chkCap = new JCheckBox("Capuccino");
    chkMocha = new JCheckBox("Mocha");
    chkChai = new JCheckBox("Chai");
    chkEspresso = new JCheckBox("Espresso");
    chkLongBlack = new JCheckBox("Long Black");
    chkFlatWhite = new JCheckBox("Flat White");

    pnlHotDrink.add(chkLatte);
    pnlHotDrink.add(chkCap);
    pnlHotDrink.add(chkMocha);
    pnlHotDrink.add(chkChai);
    pnlHotDrink.add(chkEspresso);
    pnlHotDrink.add(chkLongBlack);
    pnlHotDrink.add(chkFlatWhite);

    tabbedPane.add("Hot Drinks", pnlHotDrink);

    pane.add(tabbedPane);
}

}
Schming
  • 51
  • 7
  • 1
    I think that the best way to do it is to create a `+` button and a `-` button in the same line and between the 2 buttons add a `label` that add one for each time you click on the `+` button. – Yagami Light Jul 20 '16 at 13:19
  • Thing with UI design is: there is almost an infinite amount of options to choose from. If this is a "real" project; then you would do interviews (and probably experiments) with the people supposed to use this system. Understand what their actual tasks are; and find ways to make them happy. If it is for your learning only ... you still might to checkout stuff as https://goodui.org/ ... and then: make experiments. As Kamel said ... very often people combine buttons to inc/decrease counters; but also allowing you to directly enter numbers. But correct: there is no point in having checkboxes. – GhostCat Jul 20 '16 at 13:24
  • 2
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). (An MCVE would contain 1 checkbox, not 7.) 2) See [Detection/fix for the hanging close bracket of a code block](http://meta.stackexchange.com/q/251795/155831) for a problem I could no longer be bothered fixing. 3) Consider using a `JSpinner` with a [`SpinnerNumberModel`](https://docs.oracle.com/javase/8/docs/api/javax/swing/SpinnerNumberModel.html) in place of the check box. E.G. as seen in [this answer](http://stackoverflow.com/a/17874718/418556) for the gap & width values. – Andrew Thompson Jul 20 '16 at 13:29

0 Answers0