Advertisement
Guest User

Untitled

a guest
Apr 4th, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Font;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.net.MalformedURLException;
  7. import java.util.*;
  8.  
  9. import javax.sound.sampled.AudioFormat;
  10. import javax.sound.sampled.AudioInputStream;
  11. import javax.sound.sampled.AudioSystem;
  12. import javax.sound.sampled.Clip;
  13. import javax.sound.sampled.DataLine;
  14. import javax.sound.sampled.LineUnavailableException;
  15. import javax.sound.sampled.UnsupportedAudioFileException;
  16. import javax.swing.JLabel;
  17. import javax.swing.JOptionPane;
  18.  
  19. public class Chasi {
  20. static JLabel l1 = new JLabel();
  21. Font ft = new Font("Verdana", Font.BOLD, 32);
  22. private int a;
  23. private int b;
  24.  
  25. public void setA(int i) {
  26. a = i;
  27. }
  28.  
  29. public void setB(int f) {
  30. b = f;
  31. }
  32. public static String AM(){
  33. String s = "PM";
  34. Date d = new Date();
  35. if(d.getHours()<12){
  36. s = "AM";
  37. }
  38. return s;
  39. }
  40. private static String re = "clap.wav";
  41. public void setRe(String s){
  42. re = s;
  43. }
  44.  
  45.  
  46. public static void Play() {
  47. try {
  48. File yourFile = new File(re);
  49. AudioInputStream stream;
  50. AudioFormat format;
  51. DataLine.Info info;
  52. Clip clip;
  53.  
  54. stream = AudioSystem.getAudioInputStream(yourFile);
  55. format = stream.getFormat();
  56. info = new DataLine.Info(Clip.class, format);
  57. clip = (Clip) AudioSystem.getLine(info);
  58. clip.open(stream);
  59. clip.start();
  60. } catch (Exception e) {
  61. System.out.println("ПИЧАЛЬ БИДА");
  62. }
  63. }
  64.  
  65. public void Clock() {
  66.  
  67. Thread cl = new Thread() {
  68. public void run() {
  69. try {
  70. for (;;) {
  71. Calendar cal = new GregorianCalendar();
  72. int day = cal.get(Calendar.DAY_OF_MONTH);
  73. int month = cal.get(Calendar.MONTH);
  74. int year = cal.get(Calendar.YEAR);
  75. int second = cal.get(Calendar.SECOND);
  76. int minute = cal.get(Calendar.MINUTE);
  77. int hour = cal.get(Calendar.HOUR);
  78. String s = hour + ":" + minute + ":" + second + " " + AM();
  79. l1.setText(s);
  80. l1.setFont(ft);
  81. sleep(1000);
  82. if (hour == a && minute == b) {
  83. Play();
  84. this.stop();
  85. this.resume();
  86. }
  87.  
  88. }
  89. } catch (InterruptedException e) {
  90. // TODO Auto-generated catch block
  91. e.printStackTrace();
  92. }
  93.  
  94. }
  95. };
  96.  
  97. cl.start();
  98.  
  99. }
  100.  
  101. public static void main(String[] args) {
  102. Chasi ch = new Chasi();
  103. ch.Clock();
  104. JOptionPane.showMessageDialog(null, l1);
  105.  
  106.  
  107. }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement