当我运行此代码时:
class reclient {
String ip = "127.0.0.1";
static int serverPort = 6667;
static int serverPort1 = 6668;
static String Message,input;
public reclient(){
try{
Scanner s = new Scanner(System.in);
System.out.print("Enter Text: ");
input = s.nextLine();
InetAddress ipAddress = InetAddress.getByName(ip);
Socket socket = new Socket(ipAddress,serverPort);
OutputStream sout = socket.getOutputStream();
InputStream sin = socket.getInputStream();
DataInputStream in = new DataInputStream(sin);
DataOutputStream out = new DataOutputStream(sout);
out.writeUTF(input);
out.flush();
}catch(IOException e){
System.out.print(e.getMessage());
}
}
public static void main(String [] args){
new reclient();
try{
ServerSocket ss = new ServerSocket(serverPort1);
int i = 0;
while(true){
i++;
Socket socket = ss.accept();
OutputStream sout = socket.getOutputStream();
InputStream sin = socket.getInputStream();
DataInputStream in = new DataInputStream(sin);
DataOutputStream out = new DataOutputStream(sout);
input = in.readUTF();
System.out.println("Message [" + i + "]" +input);
}
}catch(IOException e){
System.out.print(e.getMessage());
}
}
我看到了一个消息框。但是,我无法使用鼠标光标选择消息,以便将其复制到剪贴板。
有没有办法做到这一点?
答案 0 :(得分:4)
简而言之:否。消息框由相应的平台(即Windows,Linux或MacOS)提供,您无法影响消息的呈现方式。
为了能够复制您需要创建自定义消息对话框的消息文本,该对话框使用只读文本小部件来显示消息并允许复制其内容。
您可能需要查看JFace MessageDialog
代码以获取自定义对话框的示例。