Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.Font;
- import java.io.File;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.util.*;
- import javax.sound.sampled.AudioFormat;
- import javax.sound.sampled.AudioInputStream;
- import javax.sound.sampled.AudioSystem;
- import javax.sound.sampled.Clip;
- import javax.sound.sampled.DataLine;
- import javax.sound.sampled.LineUnavailableException;
- import javax.sound.sampled.UnsupportedAudioFileException;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- public class Chasi {
- static JLabel l1 = new JLabel();
- Font ft = new Font("Verdana", Font.BOLD, 32);
- private int a;
- private int b;
- public void setA(int i) {
- a = i;
- }
- public void setB(int f) {
- b = f;
- }
- public static String AM(){
- String s = "PM";
- Date d = new Date();
- if(d.getHours()<12){
- s = "AM";
- }
- return s;
- }
- private static String re = "clap.wav";
- public void setRe(String s){
- re = s;
- }
- public static void Play() {
- try {
- File yourFile = new File(re);
- AudioInputStream stream;
- AudioFormat format;
- DataLine.Info info;
- Clip clip;
- stream = AudioSystem.getAudioInputStream(yourFile);
- format = stream.getFormat();
- info = new DataLine.Info(Clip.class, format);
- clip = (Clip) AudioSystem.getLine(info);
- clip.open(stream);
- clip.start();
- } catch (Exception e) {
- System.out.println("ПИЧАЛЬ БИДА");
- }
- }
- public void Clock() {
- Thread cl = new Thread() {
- public void run() {
- try {
- for (;;) {
- Calendar cal = new GregorianCalendar();
- int day = cal.get(Calendar.DAY_OF_MONTH);
- int month = cal.get(Calendar.MONTH);
- int year = cal.get(Calendar.YEAR);
- int second = cal.get(Calendar.SECOND);
- int minute = cal.get(Calendar.MINUTE);
- int hour = cal.get(Calendar.HOUR);
- String s = hour + ":" + minute + ":" + second + " " + AM();
- l1.setText(s);
- l1.setFont(ft);
- sleep(1000);
- if (hour == a && minute == b) {
- Play();
- this.stop();
- this.resume();
- }
- }
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- };
- cl.start();
- }
- public static void main(String[] args) {
- Chasi ch = new Chasi();
- ch.Clock();
- JOptionPane.showMessageDialog(null, l1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement