tags:

views:

27

answers:

2

If i have a method in my gui that returns a list of JButtons then in my makeFrame() method i populate my GridView with these buttons, how can i get hold of these buttons in my logic class,

the logic i am using is to check the labels of the buttons, if three in a row with the same label then win else carry on. But the logic class cant have a reference to the gui class so i am unsure how to check the labels :p

thanks

A: 

You don’t want to expose GUI elements to your logic class. Instead, expose the state of the GUI, e.g. when having a JCheckBox labelled “active”, add isActive() instead of getCheckBox() in your GUI class.

Bombe
+2  A: 

Instead of checking the actual GUI buttons your logic class should hold a model of the button state, for example, in a 2D array. You then have the state within the logic class to check for a win etc.

The buttons on the GUI should only be a representation of the state held in the logic class.

Mark