java小游戏源代码急求JAVA源代码,小游戏或者别的

java小游戏源代码  时间:2021-06-30  阅读:()

急求JAVA源代码,小游戏或者别的

//这是个聊天程序, 在ECLIPSE 运行 Client.java 就可以了。

连接是:localhost //Server 代码, package message; import java.io.*; import .*; import java.util.*; public class Server { public static void main(String[] args) throws Exception{ System.out.print("Server"); ServerSocket socket=new ServerSocket(8888); Vector v=new Vector(); while(true){ Socket sk=ept(); DataInputStream in=new DataInputStream(sk.getInputStream()); DataOutputStream out=new DataOutputStream(sk.getOutputStream()); v.add(sk); new ServerThread(in,v).start(); } } } //ServerThread.java 代码 package message; import .*; import java.io.*; import java.util.*; public class ServerThread extends Thread{ DataInputStream in; Vector all; public ServerThread(DataInputStream in,Vector v){ this.in=in; this.all=v; } public void run() { while(true) { try{ String s1=in.readUTF(); for(int i=0;i<all.size();i++) { Object obj=all.get(i); Socket socket=(Socket)obj; DataOutputStream out=new DataOutputStream(socket.getOutputStream()); out.writeUTF(s1); System.out.print(i); out.flush(); } System.out.print("Message send over!"); }catch(Exception e){e.printStackTrace();}; } } } //ClientFrame.java 代码 package message; import java.awt.*; import java.awt.event.*; import javax.swing.*; import .*; import java.io.*; public class ClientFrame extends JFrame implements ActionListener{ JButton b1=new JButton ("SendMessage"); JButton b2=new JButton("Link Server"); JTextField t1=new JTextField(20); JTextField t2=new JTextField(20); JLabel l=new JLabel("输入服务器名字:"); JTextArea area=new JTextArea(10,20); JPanel p1=new JPanel(); JPanel p2=new JPanel(); JPanel p3=new JPanel(); JPanel p4=new JPanel(); Socket socket; public ClientFrame() { this.getContentPane().add(p1); p2.add(new JScrollPane(area)); p3.add(t1); p3.add(b1); p4.add(l); p4.add(t2); p4.add(b2); p2.setLayout(new FlowLayout()); p3.setLayout(new FlowLayout()); p4.setLayout(new FlowLayout()); p1.setLayout(new BorderLayout()); p1.add("North",p2); p1.add("Center",p3); p1.add("South",p4); b1.addActionListener(this); b2.addActionListener(this); this.pack(); show(); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("Link Server")) { try{ socket=new Socket(t2.getText(),8888); b2.setEnabled(false); JOptionPane.showMessageDialog(this, "Connection ess"); DataInputStream in=new DataInputStream(socket.getInputStream()); new ClientThread(in,area).start(); } catch(Exception e1){ JOptionPane.showMessageDialog(this, "Connection Error"); e1.printStackTrace();}; } else if(e.getActionCommand().equals("SendMessage")) { try{ DataOutputStream out=new DataOutputStream(socket.getOutputStream()); out.writeUTF(t1.getText()); t1.setText(""); }catch(Exception e1){e1.printStackTrace();}; } } } //ClientThread.java 代码 package message; import .*; import java.io.*; import javax.swing.*; public class ClientThread extends Thread { DataInputStream in; JTextArea area; public ClientThread(DataInputStream in,JTextArea area){ this.in=in; this.area=area; } public void run() { while(true){ try{ String s=in.readUTF(); area.append(s); } catch(Exception e){e.printStackTrace();}; } } } //Client.java代码 package message; public class Client { /** * @param args */ public static void main(String[] args) { new ClientFrame(); } } // 每段代码都是个类,不要弄在一个文件里。

运行 Client.java good luck to you!

ProfitServer$34.56/年,5折限时促销/可选西班牙vps、荷兰vps、德国vps/不限制流量/支持自定义ISO

ProfitServer怎么样?ProfitServer好不好。ProfitServer是一家成立于2003的主机商家,是ITC控股的一个部门,主要经营的产品域名、SSL证书、虚拟主机、VPS和独立服务器,机房有俄罗斯、新加坡、荷兰、美国、保加利亚,VPS采用的是KVM虚拟架构,硬盘采用纯SSD,而且最大的优势是不限制流量,大公司运营,机器比较稳定,数据中心众多。此次ProfitServer正在对...

云基最高500G DDoS无视CC攻击(Yunbase),洛杉矶CN2GIA、国内外高防服务器

云基成立于2020年,目前主要提供高防海内外独立服务器用户,欢迎各类追求稳定和高防优质线路的用户。业务可选:洛杉矶CN2-GIA+高防(默认500G高防)、洛杉矶CN2-GIA(默认带50Gbps防御)、香港CN2-GIA高防(双向CN2GIA专线,突发带宽支持,15G-20G DDoS防御,无视CC)、国内高防服务器(广州移动、北京多线、石家庄BGP、保定联通、扬州BGP、厦门BGP、厦门电信、...

搬瓦工VPS:新增荷兰机房“联通”线路的VPS,10Gbps带宽,可在美国cn2gia、日本软银、荷兰“联通”之间随意切换

搬瓦工今天正式对外开卖荷兰阿姆斯特丹机房走联通AS9929高端线路的VPS,官方标注为“NL - China Unicom Amsterdam(ENUL_9)”,三网都走联通高端网络,即使是在欧洲,国内访问也就是飞快。搬瓦工的依旧是10Gbps带宽,可以在美国cn2 gia、日本软银与荷兰AS9929之间免费切换。官方网站:https://bwh81.net优惠码:BWH3HYATVBJW,节约6...

java小游戏源代码为你推荐
贸易配额出口配额是什么意思?ipv6电视ipv6网络电视播放器isbackground什么叫做背景反应?background reaction阶乘符号1~10的阶乘(!)分别是多少?windowsmediawindows media player 是什么啊建行手机网站怎么下载建行手机银行avc是什么格式格式工厂转的[AS3 720 AVC]mp4是什么格式avc是什么格式电厂AVC啥意思?公众号付费阅读怎么利用公众号做知识付费?shoujiao黑鲨手机SKW一AO怎么解锁?
免费ddos防火墙 亚洲小于500m 777te godaddy域名证书 日本bb瘦 宁波服务器 网站木马检测工具 刀片式服务器 isp服务商 秒杀品 游戏服务器出租 东莞主机托管 主机返佣 免费个人网页 国内空间 开心online 酷锐 防盗链 美国vpn服务器 studentmain 更多