Created
June 7, 2021 09:11
-
-
Save stk3702/99b5d3b7cb1ba91b5fc471f4c7a8acf6 to your computer and use it in GitHub Desktop.
buzzer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.event.KeyListener; | |
import java.awt.event.KeyEvent; | |
import javax.swing.JDialog; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.JLabel; | |
import javax.sound.sampled.AudioInputStream; | |
import javax.sound.sampled.AudioSystem; | |
import javax.sound.sampled.Clip; | |
import javax.swing.ImageIcon; | |
import java.applet.Applet; | |
import java.applet.AudioClip; | |
import java.net.URL; | |
import java.io.File; | |
class Buzzer extends Thread | |
{ | |
private URL url; | |
private AudioClip sound; | |
private File f; | |
public Buzzer() | |
{ | |
f=new File("f.wav"); | |
if(f.exists()) { | |
System.out.println("pouet"); | |
} | |
try | |
{ | |
url = f.toURI().toURL(); | |
sound = Applet.newAudioClip(url); | |
System.out.println("sound"); | |
} catch (Exception e) { | |
System.out.println(e); | |
} | |
} | |
public void jouer() | |
{ | |
System.out.println("in"); | |
sound.play(); | |
System.out.println("out"); | |
} | |
} | |
class FenetreQuizz extends JFrame implements KeyListener{ | |
JLabel label; | |
JPanel panel; | |
JDialog dg; | |
Buzzer bz; | |
String ficelle; | |
public FenetreQuizz () { | |
super(); | |
ficelle=""; | |
bz=new Buzzer(); | |
setTitle("Quizz"); | |
setSize(200,200); | |
setExtendedState(JFrame.MAXIMIZED_BOTH); | |
panel=new JPanel(); | |
label=new JLabel(); | |
panel.add(label); | |
setContentPane(panel); | |
setVisible(true); | |
addKeyListener(this); | |
} | |
@Override | |
public void keyPressed(KeyEvent e) { | |
if(e.getKeyCode()==KeyEvent.VK_A) { | |
ficelle=ficelle+"1"; | |
bz.jouer(); | |
} | |
} | |
@Override | |
public void keyTyped(KeyEvent e) {} | |
@Override | |
public void keyReleased(KeyEvent e) {} | |
} | |
public class Quizz{ | |
public Quizz() {} | |
public static void main(String [] args) { | |
FenetreQuizz fq=new FenetreQuizz(); | |
fq.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment