Added sound, edited image key 1

This commit is contained in:
WickedJack99
2022-06-07 00:07:55 +02:00
parent 5e196c669e
commit ae6582a282
6 changed files with 39 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -40,7 +40,7 @@ public class MyImages {
e.printStackTrace();
}
return oDefaultLightKeyboardBufferedImage.getScaledInstance(69, 62, Image.SCALE_SMOOTH);
return oDefaultLightKeyboardBufferedImage.getScaledInstance(68, 61, Image.SCALE_SMOOTH);
}
public static Image getLight_Key_2_Two_Image() {

View File

@@ -49,7 +49,7 @@ public class MyLayeredKeyboardPanel extends JPanel {
aiiImages[1][2] = 0;
//1 / ! Key
aiiImages[2][1] = 142;
aiiImages[2][1] = 143;
aiiImages[2][2] = 0;
//2 / @ Key

View File

@@ -1,5 +1,10 @@
package View.MainFrame;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
@@ -7,6 +12,8 @@ import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
public class MyMainFrame extends JFrame implements KeyListener {
@@ -14,8 +21,27 @@ public class MyMainFrame extends JFrame implements KeyListener {
private String sApplicationTitle = "Learning is KEYboard";
private File oSoundFile = new File("Learning_is_keyboard/sound/sound_error.wav");
private AudioInputStream soundErrorAudioStream;
private Clip clip;
public MyMainFrame() {
try {
soundErrorAudioStream = AudioSystem.getAudioInputStream(oSoundFile);
clip = AudioSystem.getClip();
clip.open(soundErrorAudioStream);
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.setTitle(sApplicationTitle);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(true);
@@ -47,7 +73,6 @@ public class MyMainFrame extends JFrame implements KeyListener {
public void keyTyped(KeyEvent e) {
//Invoked when a key is typed. Uses KeyChar, char output
}
@Override
@@ -58,15 +83,19 @@ public class MyMainFrame extends JFrame implements KeyListener {
//Row 1
case ('`'): {
oKeyboardPanel.setImage(1, 1);
clip.start();
}break;
case ('~'): {
oKeyboardPanel.setImage(1, 1);
clip.start();
}break;
case ('1'): {
oKeyboardPanel.setImage(1, 2);
clip.start();
}break;
case ('!'): {
oKeyboardPanel.setImage(1, 2);
clip.start();
}break;
case ('2'): {
oKeyboardPanel.setImage(1, 3);
@@ -396,22 +425,29 @@ public class MyMainFrame extends JFrame implements KeyListener {
public void keyReleased(KeyEvent e) {
//Called whenever a button is released
switch (e.getKeyChar()) {
//Row 1
case ('`'): {
oKeyboardPanel.setImage(0, 1);
clip.setMicrosecondPosition(0);
}break;
case ('~'): {
oKeyboardPanel.setImage(0, 1);
clip.setMicrosecondPosition(0);
}break;
case ('1'): {
oKeyboardPanel.setImage(0, 2);
clip.setMicrosecondPosition(0);
}break;
case ('!'): {
oKeyboardPanel.setImage(0, 2);
clip.setMicrosecondPosition(0);
}break;
case ('2'): {
oKeyboardPanel.setImage(0, 3);
clip.setMicrosecondPosition(0);
}break;
case ('@'): {
oKeyboardPanel.setImage(0, 3);