progress so far

This commit is contained in:
s452635 2021-10-13 10:06:38 +02:00
parent 70f28deda2
commit 1b8dfd8fa3
2 changed files with 43 additions and 9 deletions

View File

@ -1,19 +1,37 @@
public class Order
{
int tableNo;
String status;
Object[] food;
Status status;
String[] orderedItems;
public Order( int tableNo, String status, Object[] food )
public Order( int tableNo, Status status, String[] orderedItems )
{
this.tableNo = tableNo;
this.status = status;
this.food = food;
this.orderedItems = orderedItems;
}
@Override
public String toString()
{
return "table " + tableNo + ": " + status;
String orderedItemsString = String.join( ", ", orderedItems );
if( orderedItemsString.length() > 25 )
{
orderedItemsString = orderedItemsString.substring( 0, 25 ) + "...";
}
return String.format(
"[%s] table %d: %s",
status,
tableNo,
orderedItemsString
);
}
public enum Status
{
QUEUE,
SERVED
}
}

View File

@ -1,6 +1,7 @@
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.Arrays;
public class ServersAssistantMockupFrame extends JFrame
{
@ -10,6 +11,7 @@ public class ServersAssistantMockupFrame extends JFrame
private final JButton btnNewOrder = new JButton( "NEW ORDER" );
private final JButton btnServe = new JButton( "SERVE" );
private final JButton btnCheck = new JButton( "CHECK" );
private final JTextField fieldTableNo = new JTextField( "" );
private final int MAIN_LAYOUT_GAP = 10;
private final JPanel optionPanel = new JPanel();
@ -104,7 +106,13 @@ public class ServersAssistantMockupFrame extends JFrame
"new order",
JOptionPane.PLAIN_MESSAGE
);
orders.addElement( new Order( 12, orderedItems.elementAt( 1 ), orderedItems.toArray() ) );
orders.addElement( new Order(
Integer.decode( fieldTableNo.getText() ),
Order.Status.QUEUE,
Arrays.copyOf( orderedItems.toArray(), orderedItems.getSize(), String[].class)
) );
orderedItems.clear();
fieldTableNo.setText( "" );
// component interaction
listOrders.clearSelection();
@ -114,7 +122,7 @@ public class ServersAssistantMockupFrame extends JFrame
private void serveClicked()
{
orders.remove( listOrders.getSelectedIndex() );
listOrders.getSelectedValue().status = Order.Status.SERVED;
// component interaction
listOrders.clearSelection();
@ -124,6 +132,13 @@ public class ServersAssistantMockupFrame extends JFrame
private void checkClicked()
{
JOptionPane.showMessageDialog(
this,
listOrders.getSelectedValue().orderedItems,
"table " + listOrders.getSelectedValue().tableNo,
JOptionPane.PLAIN_MESSAGE
);
// component interaction
listOrders.clearSelection();
btnServe.setEnabled( false );
@ -144,8 +159,8 @@ public class ServersAssistantMockupFrame extends JFrame
private void setUpOptionPanel()
{
// TODO : move those
String[] drinks = { "soda", "pop", "coke" };
String[] meals = { "pizza", "spaghetti", "curry" };
String[] drinks = { "coffee", "water", "tea" };
String[] meals = { "pizza", "spaghetti", "burger" };
// region COMPONENTS
@ -182,6 +197,7 @@ public class ServersAssistantMockupFrame extends JFrame
);
optionPanel.setLayout( new BoxLayout( optionPanel, BoxLayout.Y_AXIS ) );
optionPanel.add( fieldTableNo );
optionPanel.add( scrollOrderedItems );
optionPanel.add( tabbedPanel );
}