?? broadcast.java
字號:
/*
* BroadCast.java
*
* Created on 2007年7月1日, 下午5:04
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package trans;
/**
*
* @author 鵬飛
*/
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class BroadCast implements Runnable
{
private InetAddress address;
private char op;
private String mes;
public BroadCast(char op,InetAddress address,String mes)
{
this.address = address;
this.op = op;
this.mes = mes;
}
public void run()
{
String newStr = "";
if(op == 'S' || op == 'R' || op == 'M' || op == 'A')
{
newStr += op;
newStr += mes;
}
else
{
JOptionPane.showMessageDialog(null,"無該操作!","錯誤", JOptionPane.ERROR_MESSAGE);
return;
}
try{
DatagramSocket clientSocket = new DatagramSocket();
byte data[] = newStr.getBytes("UTF-8");
DatagramPacket theOut = new DatagramPacket(data,data.length,address,2007);
clientSocket.send( theOut );
clientSocket.close();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage() + this.getClass ().toString (),"錯誤", JOptionPane.ERROR_MESSAGE);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -