Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedInputStream;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.Socket;
- import java.net.URI;
- import java.net.URISyntaxException;
- import javafx.scene.media.Media;
- import javafx.scene.media.MediaPlayer;
- import javax.swing.JOptionPane;
- import javazoom.jl.decoder.JavaLayerException;
- import javazoom.jl.player.Player;
- public class MainComponent {
- public Socket server;
- public DataInputStream input;
- public DataOutputStream output;
- boolean soundPlaying = false;
- public Player player;
- public MainComponent() {
- connect();
- }
- public void connect() {
- while(true) {
- try {
- server = new Socket("127.0.0.1", 1617);
- input = new DataInputStream(server.getInputStream());
- output = new DataOutputStream(server.getOutputStream());
- while(server != null) {
- String msg = input.readUTF();
- if(msg != null) {
- if(msg.charAt(0) == 'w' && msg.charAt(1) == 'e' && msg.charAt(2) == 'b' && msg.charAt(3) == ' ') {
- java.awt.Desktop.getDesktop().browse(new URI(msg.substring(4)));
- } else if(msg.charAt(0) == 'm' && msg.charAt(1) == 's' && msg.charAt(2) == 'g' && msg.charAt(3) == ' ') {
- JOptionPane.showMessageDialog(null, msg.substring(4));
- } else if(msg.charAt(0) == 's' && msg.charAt(1) == 'n' && msg.charAt(2) == 'd' && msg.charAt(3) == ' ') {
- InputStream fis = MainComponent.class.getResourceAsStream("/dad.mp3");
- player = new Player(fis);
- if(!soundPlaying) {
- soundPlaying = true;
- player.play();
- } else {
- }
- }
- }
- }
- } catch(IOException e) {
- } catch(URISyntaxException e2) {
- } catch(JavaLayerException e3) {
- }
- }
- }
- public static void main(String[] args) {
- new MainComponent();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement