Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import java.io.BufferedInputStream;
  2. import java.io.DataInputStream;
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.net.Socket;
  7. import java.net.URI;
  8. import java.net.URISyntaxException;
  9.  
  10. import javafx.scene.media.Media;
  11. import javafx.scene.media.MediaPlayer;
  12.  
  13. import javax.swing.JOptionPane;
  14.  
  15. import javazoom.jl.decoder.JavaLayerException;
  16. import javazoom.jl.player.Player;
  17.  
  18.  
  19.  
  20. public class MainComponent {
  21.  
  22. public Socket server;
  23.  
  24. public DataInputStream input;
  25. public DataOutputStream output;
  26.  
  27. boolean soundPlaying = false;
  28.  
  29. public Player player;
  30.  
  31. public MainComponent() {
  32. connect();
  33. }
  34.  
  35. public void connect() {
  36. while(true) {
  37. try {
  38. server = new Socket("127.0.0.1", 1617);
  39.  
  40. input = new DataInputStream(server.getInputStream());
  41. output = new DataOutputStream(server.getOutputStream());
  42.  
  43. while(server != null) {
  44. String msg = input.readUTF();
  45. if(msg != null) {
  46. if(msg.charAt(0) == 'w' && msg.charAt(1) == 'e' && msg.charAt(2) == 'b' && msg.charAt(3) == ' ') {
  47. java.awt.Desktop.getDesktop().browse(new URI(msg.substring(4)));
  48. } else if(msg.charAt(0) == 'm' && msg.charAt(1) == 's' && msg.charAt(2) == 'g' && msg.charAt(3) == ' ') {
  49. JOptionPane.showMessageDialog(null, msg.substring(4));
  50. } else if(msg.charAt(0) == 's' && msg.charAt(1) == 'n' && msg.charAt(2) == 'd' && msg.charAt(3) == ' ') {
  51. InputStream fis = MainComponent.class.getResourceAsStream("/dad.mp3");
  52. player = new Player(fis);
  53. if(!soundPlaying) {
  54. soundPlaying = true;
  55. player.play();
  56. } else {
  57.  
  58. }
  59. }
  60. }
  61. }
  62. } catch(IOException e) {
  63.  
  64. } catch(URISyntaxException e2) {
  65. } catch(JavaLayerException e3) {
  66. }
  67. }
  68. }
  69.  
  70. public static void main(String[] args) {
  71. new MainComponent();
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement