Fixed the keyboard
[BrainSamurai.git] / zbrainz / source / com / zbrainz / gui / EK1.java
blobbc2b9e2e6c65be3373d25ec01df34ff24b1478bd
1 package com.zbrainz.gui;
2 import javax.swing.*;
3 import java.awt.event.*;
4 import java.awt.*;
5 import com.zbrainz.util.*;
9 public class EK1
11 JFrame m_frame;
12 ZPanel m_panel;
13 com.zbrainz.gui.ZKeyBoard m_KBgui;
14 com.zbrainz.util.SoundBox m_KBsound;
17 public static void main( String[] args )
19 ZLog.init();
20 EK1 gui = new EK1();
21 gui.go();
22 }// main
25 public void go ()
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();
35 m_frame.add(m_panel);
36 m_KBsound.Start();
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");
49 m_KBgui.draw(g);
53 public void mousePressed(MouseEvent e)
55 int x = e.getX();
56 int y = e.getY();
57 int i = m_KBgui.convertMouseClickToKey(x, y);
58 ZLog.logInfo("Key Press event");
59 if ( i >= 0 )
61 m_KBgui.keyPressed(i);
62 m_KBsound.PlayStart(24+i);
63 ZLog.logInfo("Key Pressed[%d]\n", i);
65 m_frame.requestFocus();
66 repaint();
69 public void mouseReleased(MouseEvent e)
71 int x = e.getX();
72 int y = e.getY();
73 int i = m_KBgui.convertMouseClickToKey(x, y);
74 ZLog.logInfo("Key release event");
75 if ( i >= 0 )
77 m_KBgui.keyReleased(i);
78 m_KBsound.PlayStop(24+i);
79 ZLog.logInfo("Key Released[%d]\n", i);
81 m_frame.requestFocus();
82 repaint();
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)
102 int i = -1;
103 char c = e.getKeyChar();
104 c = Character.toLowerCase(c);
105 ZLog.logInfo("KeyPressed Event : %c", c);
106 if (c == 'a') i=0;
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;
120 if ( i < 0 ) return;
121 this.requestFocus();
122 m_KBgui.keyPressed(i);
123 m_KBsound.PlayStart(48+i);
124 this.repaint();
125 m_frame.requestFocus();
128 public void keyReleased(KeyEvent e)
130 int i = -1;
131 char c = e.getKeyChar();
132 c = Character.toLowerCase(c);
133 ZLog.logInfo("KeyReleased Event : %c", c);
134 if (c == 'a') i=0;
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;
147 if ( i < 0 ) return;
149 m_frame.requestFocus();
150 m_KBgui.keyReleased(i);
151 m_KBsound.PlayStop(24+i);
152 this.repaint();
153 m_frame.requestFocus();
156 public void keyTyped(KeyEvent e)
158 char c = e.getKeyChar();
159 m_frame.requestFocus();