Java Reference
In-Depth Information
File: its/MouseEvents/MouseEventDriver.java
package its.MouseEvents;
1.
2.
3.
public class MouseEventDriver
4.
{
5.
public static void main(String[] args)
6.
{
7.
MouseEventFrame MEF = new MouseEventFrame();
8.
MEF.showIt();
9.
}
10.
}
Exercises
6.1
Change the status panel such that instead of the number of all clicks, the
number of clicks of the right and left buttons are displayed separately. Aug-
ment the mouse listener such that these functions work. Recall that the class
SwingUtilites provides methods to check which button was used.
6.2
Add the following function to the application described in Section 6.4. If the
mouse is in the 'upper left corner' of the MouseEventPanel then the colour
of this panel changes to yellow. By the upper left corner we mean the x - and
y -coordinates of the click position are both less than 50. If the mouse is inside
of the MouseEventPanel but outside the upper left corner then the colour
is white.
Hint: Find out which listeners have to be modified. If necessary, pass more
references to the listeners in their constructors. To change the colour of a
panel use the following two commands:
this .setBackground(Color.yellow);
this .repaint();
6.3
Remove the status panel from the application and display the information in
the MouseEventPanel .Donot embed any components into that panel, use
paintComponent .
Search WWH ::




Custom Search