forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse_Demo.java
More file actions
55 lines (45 loc) · 1.56 KB
/
Mouse_Demo.java
File metadata and controls
55 lines (45 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package applet;
import java.applet.Applet;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@SuppressWarnings("serial")
public class Mouse_Demo extends Applet {
@Override
public void init() {
// TODO Auto-generated method stub
setBackground(Color.cyan);
addMouseListener(new MouseAdapter() //this mechanism is clla inner anonymous class
{
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
setBackground(Color.BLUE);
}
}
);
}
/*public void mouseClicked(MouseEvent arg0) { if we implements mouselistner then we have to define all the methods of that interface
* but if we want only one method click the we have to extend class mouse addpter but multiple extends are not allow in java
* so we declare another class and extend mouse adapter from that class constructor we call super class constructor then also code
* is increase so it is not batterr idea so we have to do different for reduce the code.
// TODO Auto-generated method stub
setBackground(Color.BLUE);
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
setBackground(Color.GRAY);
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
setBackground(Color.GREEN);
}
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
setBackground(Color.ORANGE);
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}*/
}
/*class ABC extends MouseAdapter*/