So I'm doing this simple draw program where I let the user click a button, i.e. Rectangle, and then click any desired place on the JFrame to draw it. Now, I want the user to first click on the JButton, then click anywhere on the JFrame (so that I get the X and Y coordinates) in order to draw, but I don't seem to be able to use Mouse Event mouseClicked on two things. It worked when I had the event.getSource() for the button only, but I want the user to click the button, then the desired drawing position, here's the part of the code that I'm struggling with:
public void mouseClicked (MouseEvent event)
{
if (event.getSource() == rectangle_button) //rectangle_button is a JButton that I created before
{
if (event.getSource() == panel) //panel is a JPanel that exists anywhere in the frame
{
JOptionPane.showMessageDialog(null, "rectangle is drawn");
}
}
Thanks for any help.