📄 terminate.java
字号:
package com.ter;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
class TerWin extends JFrame {
private String terName;
private String nextAddr;
private int nextPort;
private Socket s = null;
private JTextField jtf1, jtf2;
private JButton jbsend, jbcancel;
private JLabel jl1, jl2,jl3,jl4;
private boolean stopAccessFalg;
static BufferedReader br = null;
static PrintWriter pw = null;
public String getTerName() {
return terName;
}
public TerWin(String terName,String nextAddr,int nextPort) {
this.terName = terName;
this.nextAddr=nextAddr;
this.nextPort=nextPort;
setTitle("TerWin");
Container ca = getContentPane();
ca.setLayout(new GridLayout(3, 2));
//jl1 = new JLabel("下一跳选项");
jl2 = new JLabel("信息");
jl3 = new JLabel(nextAddr);
jl4 = new JLabel(terName);
//jtf1 = new JTextField();
jtf2 = new JTextField();
jbsend = new JButton("发送");
jbcancel = new JButton("取消");
jbsend.addActionListener(new OnSend());
jbcancel.addActionListener(new OnCan());
//ca.add(jl1);
//ca.add(jtf1);
ca.add(jl2);
ca.add(jtf2);
ca.add(jbsend);
ca.add(jbcancel);
ca.add(jl3);
ca.add(jl4);
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void flash() {
}
class OnSend implements ActionListener {
public void actionPerformed(ActionEvent e) {
String msg=null;
if (TerWin.pw == null) {
Socket s;
try {
s = new Socket(nextAddr, nextPort);
OutputStream os = null;
os = s.getOutputStream();
PrintWriter pw = new PrintWriter(os, true);
TerWin.pw = pw;
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
msg = jtf2.getText();
msg += ":" + TerWin.this.getTerName() + "->";
System.out.println(msg);
TerWin.pw.println(msg);
}
}
class OnCan implements ActionListener {
public void actionPerformed(ActionEvent e) {
TerWin.this.dispose();
}
}
}
public class Terminate extends Thread {
public String nodeName;
public String nextAddr;
public int nextPort;
public Terminate(String nodeName,String nextAddr,int nextPort) {
super();
this.nodeName = nodeName;
this.nextAddr=nextAddr;
this.nextPort=nextPort;
}
public void run() {
TerWin tw = new TerWin(nodeName,nextAddr,nextPort);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -