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!

Sharktech云服务器35折年付33美元起,2G内存/40G硬盘/4TB流量/多机房可选

Sharktech又称SK或者鲨鱼机房,是一家主打高防产品的国外商家,成立于2003年,提供的产品包括独立服务器租用、VPS云服务器等,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹等。之前我们经常分享商家提供的独立服务器产品,近期主机商针对云虚拟服务器(CVS)提供优惠码,优惠后XS套餐年付最低仅33.39美元起,支持使用支付宝、PayPal、信用卡等付款方式。下面以XS套餐为例,分享产品配...

GreenCloudVPS$20/年,新加坡/美国/荷兰vps/1核/1GB/30GB,NVMe/1TB流量/10Gbps端口/KVM

greencloudvps怎么样?greencloudvps是一家国外主机商,VPS数据中心多,之前已经介绍过多次了。现在有几款10Gbps带宽的特价KVM VPS,Ryzen 3950x处理器,NVMe硬盘,性价比高。支持Paypal、支付宝、微信付款。GreenCloudVPS:新加坡/美国/荷兰vps,1核@Ryzen 3950x/1GB内存/30GB NVMe空间/1TB流量/10Gbps...

华纳云不限流量¥324/年,香港双向CN2(GIA)云服务器/1核1G/50G存储/2Mbps

华纳云(HNCloud Limited)是一家专业的全球数据中心基础服务提供商,总部在香港,隶属于香港联合通讯国际有限公司,拥有香港政府颁发的商业登记证明,保证用户的安全性和合规性。 华纳云是APNIC 和 ARIN 会员单位。主要提供香港和美国机房的VPS云服务器和独立服务器。商家支持支付宝、网银、Paypal付款。华纳云主要面向国内用户群,所以线路质量还是不错的,客户使用体验总体反响还是比较好...

java小游戏源代码为你推荐
chartboost如何在Chartboost后台建立广告windowsmediawindows media player打开怎么设置素数算法什么是素数算法代发邮件邮件代发会不会有短信代发那么好的市场效益呢?公众号付费阅读目前公众号有没有的付费问答平台可以提供的?音乐代码在html中插入mp3音频的代码是什么网络安全密钥一般路由器是网络安全密钥是多少方正证券官方网方正证券同花顺下载/2010同花顺官方网站/同花顺官方网站首页yui3yui 3 月9日 出的专辑的情报ocr软件下载如何安装汉王ocr文字识别软件
韩国虚拟主机 工信部域名备案 免费cn域名 联通c套餐 hawkhost优惠码 便宜域名 网站监控 回程路由 智能骨干网 卡巴斯基官方免费版 炎黄盛世 web服务器的架设 hkt 双线机房 域名dns 双线asp空间 云服务器比较 购买空间 买空间网 闪讯网 更多