?? crcserver.java
字號:
import java.awt.*;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.BevelBorder;
public class CrcServer extends JFrame {
JLabel l = new JLabel("輸入協商多項式");
JTextField tf = new JTextField();
JTextField info = new JTextField("info");
JButton bt = new JButton("提交");
int[] p;
boolean flag = false;
public static void main(String[] args) {
new CrcServer().ServerView();
}
void ServerView() {
l.setBounds(80, 100, 100, 30);
l.setBorder(new BevelBorder(1, Color.BLUE, Color.BLUE));
tf.setBounds(200, 100, 100, 30);
bt.setBounds(320, 100, 70, 30);
bt.setBorder(new BevelBorder(1, Color.BLUE, Color.BLUE));
info.setBounds(80, 150, 250, 30);
info.setEnabled(false);
this.setSize(500, 300);
this.setLocation(100, 100);
this.setVisible(true);
this.setLayout(null);
this.add(tf);
this.add(bt);
this.add(l);
this.add(info);
btLis b1 = new btLis();
bt.addActionListener(b1);
this.setBackground(Color.lightGray);
// this.setResizable(false);
this.setTitle("計科061319 肖亮");
this.addWindowListener(new MyWindowMonitor());
}
class MyWindowMonitor extends WindowAdapter {
public void windowClosing(WindowEvent e) {
setVisible(false);
// notconnect();
System.exit(0);
}
}
class btLis implements ActionListener {
public void actionPerformed(ActionEvent e) {
flag = true;
try {
String num = tf.getText();
int x = num.length();
p = new int[x];
if (x > 0) {
for (int i = 0; i < num.length(); i++) {
int j = num.charAt(i) - 48;
if (i == 0 || i == num.length() - 1) {
if (j == 0) {
tf.setText("");
info.setText("輸入有錯,請重新輸入");
flag = false;
} else if (j == 0 || j == 1) {
p[i] = j;
} else {
tf.setText("");
info.setText("輸入有錯,請重新輸入");
flag = false;
}
}
if (j == 0 || j == 1) {
p[i] = j;
} else {
tf.setText("");
info.setText("輸入有錯,請重新輸入");
flag = false;
}
}
} else {
info.setText("請輸入多項式");
flag = false;
}
for (int i = 0; i < p.length; i++) {
System.out.println(p[i]);
}
} catch (NumberFormatException e1) {
tf.setText("");
info.setText("輸入有錯,請重新輸入");
flag = false;
// e1.printStackTrace();
}
if (flag) {
dispose();
ReThread r = new ReThread();
r.start();
new CrcSend(p).SendView();
// new CrcRecieve(p).RecieveView();
}
}
}
class ReThread extends Thread {
public void run() {
new CrcRecieve(p).RecieveView();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -