Hi,
I have to add a mouse over event and mouse click event in my rectangles that I draw while taking the values from an input file. Now since I am taking rectangle height and width from the input text file as well I also want to take a text value to be shown while moving a mouse over a particular rectangle from my input file. Also when user clicks on that rectangle the height and width of that particular rectangle only should be displayed (re-adjusted).
Like suppose my input file has 3 fields:-
Now When my paint component draws these 2 rectangles and a user moves his mouse over the rectangle he should see text message attached to it:- Like for first row 10, 23 he should see "Hello". In this case when he clicks on this rectangle the picture should read just to show only 10 and 20 as height and width. Now the problem is I am confused where to add the mouse and mouse click event function.
I am planning to add it like this in paintcomponent method:-
and then write a new functions like this:-
Would it be the correct way to do it ? I am doing mouse over functions for the first time so donno much about there usage.
I would be enlightened to get help and advice smile.gif
I am extending my JPanel like this:-
Thanks
I have to add a mouse over event and mouse click event in my rectangles that I draw while taking the values from an input file. Now since I am taking rectangle height and width from the input text file as well I also want to take a text value to be shown while moving a mouse over a particular rectangle from my input file. Also when user clicks on that rectangle the height and width of that particular rectangle only should be displayed (re-adjusted).
Like suppose my input file has 3 fields:-
Code:
Height Width Test_To_Show 10 23 Hello 20 44 Bye
I am planning to add it like this in paintcomponent method:-
Code:
for(int i=0; i<myarraylist.size(); i++){
Coloring fc = myarraylist.get(i);
GradientPaint gpi = new GradientPaint(0, 0,c.getColor() , 0, 20, Color.white, true);
g2d.setPaint(gpi);
g2d.drawRect(fc.value1, 29, fc.mywidth, 83);
g2d.fillRect(fc.value1, 29, fc.mywidth, 83);
fc.addMouseMotionListener(this);
fc.addMouseListener(this);
}
Code:
public void mouseEntered(MouseEvent e) {
//I will be reading from a file and then pass the string that I want to show as text while mouse over
String s = // takes value from the inpuf file.
fc.setText(s);
}
public void mouseClicked(MouseEvent e) {
//same way reading from the file ... Not sure how I will do this one
}
I would be enlightened to get help and advice smile.gif
I am extending my JPanel like this:-
Code:
public class Testing extends JPanel implements MouseListener {
Comment