Following are the steps to add the corresponding UI logic for the table clicking part:
Implement the
itemClick
method as follows:BoxwordsUI extends UI implements ItemClickListener { // ... public void itemClick(ItemClickEvent event) { Property property = event.getItem().getItemProperty( event.getPropertyId()); if (".".equals(property.getValue())) { property.setValue(game.getCurrentLetter()); nextTurn(); } else { Notification.show("You must select an empty cell."); } } // ... }
Run the application and perform some clicks on the table.
The event
variable gives us all we need to know about the performed click. We are using an ItemClickListener
, right? This means that our method will be called every time the user clicks on an Item
, and an Item
is a row. But we need to know not only the row, but also the column. More precisely, we need the exact cell, and for a table, a cell is the same as a...