1 package com
.zbrainz
.gui
;
3 import java
.awt
.event
.*;
5 import com
.zbrainz
.util
.*;
13 com
.zbrainz
.gui
.ZKeyBoard m_KBgui
;
14 com
.zbrainz
.util
.SoundBox m_KBsound
;
17 public static void main( String
[] args
)
27 com
.zbrainz
.util
.ALibUtil
.enableDebug();
28 m_frame
= new JFrame();
29 m_frame
.setDefaultCloseOperation( JFrame
.EXIT_ON_CLOSE
);
30 m_frame
.setSize(900, 400);
32 m_KBgui
= new com
.zbrainz
.gui
.ZKeyBoard(20, 30, 18, 100, 6);
33 m_KBsound
= new com
.zbrainz
.util
.SoundBox(0);
34 m_panel
= new ZPanel();
37 m_panel
.setBackground(Color
.YELLOW
);
38 m_panel
.addMouseListener(m_panel
);
39 m_frame
.addKeyListener(m_panel
);
40 m_frame
.setVisible(true);
44 public class ZPanel
extends JPanel
implements MouseListener
, KeyListener
46 public void paintComponent( Graphics g
)
48 ZLog
.logInfo("Hello");
53 public void mousePressed(MouseEvent e
)
57 int i
= m_KBgui
.convertMouseClickToKey(x
, y
);
58 ZLog
.logInfo("Key Press event");
61 m_KBgui
.keyPressed(i
);
62 m_KBsound
.PlayStart(24+i
);
63 ZLog
.logInfo("Key Pressed[%d]\n", i
);
65 m_frame
.requestFocus();
69 public void mouseReleased(MouseEvent e
)
73 int i
= m_KBgui
.convertMouseClickToKey(x
, y
);
74 ZLog
.logInfo("Key release event");
77 m_KBgui
.keyReleased(i
);
78 m_KBsound
.PlayStop(24+i
);
79 ZLog
.logInfo("Key Released[%d]\n", i
);
81 m_frame
.requestFocus();
85 public void mouseEntered(MouseEvent e
)
87 m_frame
.requestFocus();
90 public void mouseExited(MouseEvent e
)
92 m_frame
.requestFocus();
95 public void mouseClicked(MouseEvent e
)
97 m_frame
.requestFocus();
100 public void keyPressed(KeyEvent e
)
103 char c
= e
.getKeyChar();
104 c
= Character
.toLowerCase(c
);
105 ZLog
.logInfo("KeyPressed Event : %c", c
);
107 else if (c
== 'w') i
=1;
108 else if (c
== 's') i
=2;
109 else if (c
== 'e') i
=3;
110 else if (c
== 'd') i
=4;
111 else if (c
== 'h') i
=5;
112 else if (c
== 'u') i
=6;
113 else if (c
== 'j') i
=7;
114 else if (c
== 'i') i
=8;
115 else if (c
== 'k') i
=9;
116 else if (c
== 'o') i
=10;
117 else if (c
== 'l') i
=11;
118 else if (c
== ';') i
=12;
122 m_KBgui
.keyPressed(i
);
123 m_KBsound
.PlayStart(48+i
);
125 m_frame
.requestFocus();
128 public void keyReleased(KeyEvent e
)
131 char c
= e
.getKeyChar();
132 c
= Character
.toLowerCase(c
);
133 ZLog
.logInfo("KeyReleased Event : %c", c
);
135 else if (c
== 'w') i
=1;
136 else if (c
== 's') i
=2;
137 else if (c
== 'e') i
=3;
138 else if (c
== 'd') i
=4;
139 else if (c
== 'h') i
=5;
140 else if (c
== 'u') i
=6;
141 else if (c
== 'j') i
=7;
142 else if (c
== 'i') i
=8;
143 else if (c
== 'k') i
=9;
144 else if (c
== 'o') i
=10;
145 else if (c
== 'l') i
=11;
146 else if (c
== ';') i
=12;
149 m_frame
.requestFocus();
150 m_KBgui
.keyReleased(i
);
151 m_KBsound
.PlayStop(24+i
);
153 m_frame
.requestFocus();
156 public void keyTyped(KeyEvent e
)
158 char c
= e
.getKeyChar();
159 m_frame
.requestFocus();