I am trying to create a JButton that will know whether or not it was right or left clicked when it was pressed. Here is my action listener for the JButton
buttons[i][j].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JButton button=(JButton)e.getSource();
StringTokenizer st=new StringTokenizer(button.getName());
}
});
And here is my code for the Mouse listener
public void mouseClicked(MouseEvent event){
if(event.getButton()==1)
{
startPosition.move(event.getX(),event.getY());
System.out.println(startPosition.getLocation());
System.out.println("row="+row+" column="+column);
}
else
{
endPosition.move(event.getX(),event.getY());
System.out.println("row="+row+" column="+column);
}
}
I know how to tell whether or now the mouse was right or left clicked, but I can't figure out how to combine that with the action event of the button being pressed. Any help would be much appreciated. Thanks.