-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterTestClass.java
More file actions
57 lines (47 loc) · 1.19 KB
/
AdapterTestClass.java
File metadata and controls
57 lines (47 loc) · 1.19 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
56
57
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class AdapterTestClass extends JFrame implements ActionListener{
int X , Y ;
String str;
JButton b ;
JLabel l;
public AdapterTestClass()
{
super("The Mouse Motion Adapter");
getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
JPanel p =new JPanel();
p.setLayout(new FlowLayout());
l = new JLabel(str + X + Y );
getContentPane().add(l,"South");
b = new JButton("Quit");
b.addActionListener(this);
p.add(b);
getContentPane().add(p);
addMouseMotionListener(new ListenerClass());
setSize(300,300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
String s= ae.getActionCommand();
if ( "Quit".equals(s))
{
System.exit(0);
}
}
public static void main(String args[])
{
AdapterTestClass f = new AdapterTestClass();
}
}
class ListenerClass extends MouseMotionAdapter
{
public void mouseDragged(MouseEvent me)
{
AdapterTestClass AT;
AT = (AdapterTestClass)me.getSource();
AT.l.setText("Mouse draggeded at:" + me.getX()+ "," + me.getY());
AT.l.setForeground(Color.red);
}
}