-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathawt_example.java
executable file
·117 lines (102 loc) · 3.04 KB
/
awt_example.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import java.io.*;
import java.awt.*;
import java.awt.event.*;
// êëàññ ñëåäèò çà çàêðûòèåì îêîííûìè ñîîáùåíèÿìè
class windowstate extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.out.println("close");
((Window)(e.getSource())).dispose();
}
}
// êëàññ ñëåäèò çà ñîáûòèåì Action
class actionlistener implements ActionListener{
Frame frame;
actionlistener(Frame f){
this.frame=f;
}
public void actionPerformed(ActionEvent e) {
Button button;
if(e.getSource() instanceof Button){
button=(Button)e.getSource();
Button temp_button=new Button("close");
System.out.println("Height:"+button.getHeight()+" Width:"+button.getWidth());
Dialog dialog=new Dialog(this.frame);
dialog.add(temp_button);
dialog.addWindowStateListener(new windowstate());
dialog.show();
}
}
}
// êëàññ äëÿ îòñëåæèâàíèÿ ïåðåäâèæåíèÿ ìûøè
class mousemotion implements MouseMotionListener{
Frame frame;
mousemotion(Frame f){
this.frame=f;
}
public void mouseDragged(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("X:"+arg0.getX()+" Y:"+arg0.getY());
}
public void mouseMoved(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
// îáðàáîòêà ñîáûòèé ìûøè
class mouselistener implements java.awt.event.MouseListener{
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("mouse click");
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("mouse entered");
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("mouse exited");
}
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("mouse pressed");
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("mouse released");
}
}
// êëàññ äëÿ ïîëó÷åíèÿ äàííûõ î ïðîêðó÷èâàíèè êîëåñà ìûøè
class mousewheel implements java.awt.event.MouseWheelListener{
public void mouseWheelMoved(MouseWheelEvent arg0) {
// TODO Auto-generated method stub
System.out.println("Rotation:"+arg0.getWheelRotation());
}
}
class awt_sample{
Frame frame;
Panel panel;
Button button;
awt_sample(){
Dimension dimension=new Dimension();
dimension.height=300;
dimension.width=400;
frame=new Frame("my frame");
panel=new Panel();
button=new Button("My button");
frame.setSize(dimension);//frame.setSize(400,300);
frame.add(panel);
frame.addWindowListener(new windowstate());
panel.add(button);
button.addActionListener(new actionlistener(frame));
button.addMouseMotionListener(new mousemotion(frame));
button.addMouseListener(new mouselistener());
button.addMouseWheelListener(new mousewheel());
}
public void setvisible(boolean state){
this.frame.setVisible(state);
}
}
public class main_class {
public static void main(String args[]){
(new awt_sample()).setvisible(true);
}
}