📄 mycc.java
字号:
package jsm;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.StringTokenizer;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ScrollPaneConstants;
public class MyCC extends JFrame {
JTextPane bulletin = new JTextPane(),input = new JTextPane();
JComboBox friendName = new JComboBox(),friendIP = new JComboBox();
JTextField inputIP = new JTextField("222.18.178.210", 9),
inputName = new JTextField(10);
JButton submit = new JButton("Send");
JPanel toolsPanel = new JPanel();
JScrollPane sbulletin,sinput;
byte[] IP = new byte[4];
JLabel tip = new JLabel("IP:");
StringTokenizer ipParser;
final void kernelInitial() {
Controler.cc = bulletin;
// Sender sd = Sender.getSender();
Receiver re = Receiver.getReceiver();
re.start();
MessageHandler mh = MessageHandler.getMH();
mh.initailWorkers();
}
final void UIInitial() {
iniTools();
Container cp = getContentPane();
cp.setLayout(null);
cp.add(sbulletin);
cp.add(toolsPanel);
cp.add(sinput);
sbulletin.setBounds(10, 10, 375, 200);
sinput.setBounds(10, 270, 375, 90);
toolsPanel.setBounds(10, 220, 390, 30);
setBounds(300, 200, 400, 400);
bulletin.setEditable(false);
submit.addActionListener(new SendListener());
}
final void iniTools() {
sbulletin = new JScrollPane(bulletin,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
sinput = new JScrollPane(input,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
// toolsPanel.add(friendName);
// toolsPanel.add(friendIP);
// toolsPanel.setLayout();
toolsPanel.add(tip);
toolsPanel.add(inputIP);
// toolsPanel.add(inputName);
toolsPanel.add(submit);
}
public MyCC() {
kernelInitial();
UIInitial();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
input.requestFocus();
}
void ipParse() {
int i = 0;
String ips = inputIP.getText();
ipParser = new StringTokenizer(ips, ".");
while (ipParser.hasMoreElements()) {
String fragment = ipParser.nextToken();
int temp = Integer.parseInt(fragment);
IP[i++] = temp > 127 ? (byte) (temp - 256) : (byte) temp;
}
}
class SendListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
String ms = input.getText();
//System.out.println(ms);
if (!ms.equals("")) {
ipParse();
bulletin.setText(bulletin.getText() + "come frome : "
+ "localhost" + ' ' + "time : " + new Date()+
'\n'+ms+'\n');
input.setText("");
input.requestFocus();
Controler.sendMessage(ms, IP);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -