Hi I am very new to swing and am having some trouble trying to attach listeners to buttons in a dialog box. My current assignment question is:
Create a Java program that employs a MouseListener in a Dialog component.
My goal is to have the buttons' text display the current events that are happeneing (e.g. "Button 1" will change to "mouse pointer in 'Button 1'" or "'Button 1' has been clicked" when the different events are happening.
Here is my code so far, the problem is trying to assign each button an event. I am getting compiler errors when I try to add events to the buttons array:
Again I am very new to Java so I'm sure this has an easy solution. There is no textbook for this course and the study material is the docs.Oracle tutorials which are hard for me to understand.
You have an array of type Object, variable name buttons. Since Object doesn't have a method addMouseListener(...) the compiler will complain.
Moreover, even when you sort that out and create an array of JButton, the MouseListener will be added only after the dialog is dismissed. You will need to add the mouse listener before you show the dialog.
For your future reference, when seeking help with an error it always helps to post the entire error text without paraphrasing.
There are no new questions, but there may be new answers.