资源简介
这是个简单的网络编程课程设计,使用了JAVA语言编程,C/S结构。客户端服务器
代码片段和文件信息
import java.awt.*;
import java.awt.event.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JOptionPane;
class Client implements ActionListener {
Panel p1 p2 p3;
Label l1 l2 l3 cs1 name;
Button b1 b2 b3 b4 b5 score show fh;
TextArea ta1;
TextField t1 t2 name1;
frame f f1 f2;
Socket s1;
int i;
String rd cs2 = “0“;
InputStream sin;
OutputStream son;
DataInputStream dis;
DataOutputStream dos;
Client() {
f = new frame();
f.setBounds(100 300 600 200);
f.setLayout(new GridLayout(4 1));
p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
f.add(p1);
f.add(p2);
f.add(p3);
p1.setLayout(new FlowLayout());
p1.setVisible(false);
p3.setVisible(false);
l1 = new Label(“请输入0-100的数字“ 1);
t1 = new TextField(““ 10);
b1 = new Button(“提交“);
b2 = new Button(“重新开始“);
p1.add(l1);
p1.add(t1);
p1.add(b1);
p1.add(b2);
p2.setLayout(new FlowLayout());
t2 = new TextField(“127.0.0.1“);
b3 = new Button(“连接“);
l2 = new Label(“未连接“ 1);
p2.add(t2);
p2.add(b3);
p2.add(l2);
p3.setLayout(new FlowLayout());
cs1 = new Label(“次数:“ 1);
l3 = new Label(“没开始游戏“ 1);
b4 = new Button(“开始“);
b5 = new Button(“上传分数“);
show = new Button(“查看排名“);
p3.add(l3);
p3.add(cs1);
p3.add(b4);
p3.add(b5);
p3.add(show);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
show.addActionListener(this);
f.setVisible(true);
f.addWindowListener(new Close());
f1 = new frame();
f1.setBounds(100 300 200 100);
name = new Label(“你的大名:“);
score = new Button(“上传“);
name1 = new TextField(““);
f1.add(name);
f1.add(name1);
f1.add(score);
f1.setLayout(new GridLayout(3 1));
score.addActionListener(this);
f1.setVisible(false);
f2 = new frame();
f2.setBounds(100 300 300 300);
fh = new Button(“返回“);
ta1 = new TextArea(30 50);
f2.add(ta1);
f2.add(fh);
fh.addActionListener(this);
f2.setLayout(new GridLayout(2 1));
f2.setVisible(false);
}
public void connection(String IP) {
try {
s1 = new Socket(IP1000);
l2.setText(“连接成功“);
} catch (UnknownHostException e) {
l2.setText(“服务器连接错误!!!“);
JOptionPane.showMessageDialog(null “服务器连接错误!!!“);
e.printStackTrace();
} catch (IOException e) {
l2.setText(“服务器连接错误!!!“);
JOptionPane.showMessageDialog(null “服务器连接错误!!!“);
e.printStackTrace();
}
}
public void read() {
try {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
sin = s1.getInputStream();
dis = new DataI
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 371 2011-05-15 22:46 caishu\.classpath
文件 378 2011-05-15 22:43 caishu\.project
文件 629 2011-05-15 22:43 caishu\.settings\org.eclipse.jdt.core.prefs
文件 355 2011-05-15 22:43 caishu\bin\.classpath
文件 378 2011-05-15 22:43 caishu\bin\.project
文件 629 2011-05-15 22:43 caishu\bin\.settings\org.eclipse.jdt.core.prefs
文件 744 2011-05-17 21:50 caishu\bin\Client$Close.class
文件 1617 2011-05-17 21:50 caishu\bin\Client$MyThread.class
文件 7186 2011-05-17 21:50 caishu\bin\Client.class
文件 5343 2011-05-17 21:49 caishu\bin\Server$Client.class
文件 675 2011-05-17 21:49 caishu\bin\Server$Close.class
文件 3055 2011-05-17 21:49 caishu\bin\Server.class
文件 355 2011-05-15 22:43 caishu\src\.classpath
文件 378 2011-05-15 22:43 caishu\src\.project
文件 629 2011-05-15 22:43 caishu\src\.settings\org.eclipse.jdt.core.prefs
文件 6533 2011-05-15 22:43 caishu\src\Client.java
文件 5972 2011-05-15 23:00 caishu\src\Server.java
目录 0 2011-05-17 21:51 caishu\bin\.settings
目录 0 2011-05-17 21:51 caishu\src\.settings
目录 0 2011-05-17 21:51 caishu\.settings
目录 0 2011-05-17 21:51 caishu\bin
目录 0 2011-05-17 21:51 caishu\src
目录 0 2011-05-17 21:51 caishu
----------- --------- ---------- ----- ----
35227 23
- 上一篇:filebrowser
- 下一篇:Android屏幕适配---dimens转换工具
评论
共有 条评论