I am trying to call two methods from another class which is linked to the current class i am working in.
basically if it is a left-button click from the mouse, i want to call the addCounter method (of the myAbacus object). If it is a right button click, i need to call the removeCounter method (of the myAbacus object).
In both cases, i think i need the method parameter as thisCol (a variable which stores the column that the mouse was clicked in)
class AbacusPanel extends JPanel implements MouseListener
{
int numCols;
int numRows;
int buttonClick;
AbacusModel myAbacus;
public static void main(String[] args)
{
AbacusFrame w = new AbacusFrame();
w.setVisible(true);
}
public AbacusPanel(int nc, int nr)
{
numCols = nc;
numRows = nr;
addMouseListener(this);
myAbacus = new AbacusModel(numCols,numRows);
}
int getCol(int x)
{
return x*numCols/getWidth();
}
int getRow(int y)
{
return y*numRows/getHeight();
}
public void mouseReleased(MouseEvent event)
{
}
public void mousePressed(MouseEvent event)
{
}
public void mouseClicked(MouseEvent event)
{
int thisCol = getCol(event.getX());
System.out.println("you clicked in column " + thisCol);
System.out.println("The button clicked was " + event.getButton());
// here is where i would need to call the addCounter and removeCounter methods
// but i do not know how to call these methods correctly
}
please can anybody help me achieve this?
if you need me to explain any aspect of this program then please ask...
Thanks