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!

HostKvm香港VPS七折:$5.95/月KVM-2GB内存/40GB硬盘/500GB月流量

HostKvm是一家成立于2013年的国外主机服务商,主要提供VPS主机,基于KVM架构,可选数据中心包括日本、新加坡、韩国、美国、俄罗斯、中国香港等多个地区机房,均为国内直连或优化线路,延迟较低,适合建站或者远程办公等。商家本月针对香港国际机房提供特别7折优惠码,其他机房全场8折,优惠后2G内存香港VPS每月5.95美元起,支持使用PayPal或者支付宝付款。下面以香港国际(HKGlobal)为...

易探云:香港物理机服务器仅550元/月起;E3-1230/16G DDR3/SATA 1TB/香港BGP/20Mbps

易探云怎么样?易探云(yitanyun.com)是一家知名云计算品牌,2017年成立,从业4年之久,目前主要从事出售香港VPS、香港独立服务器、香港站群服务器等,在售VPS线路有三网CN2、CN2 GIA,该公司旗下产品均采用KVM虚拟化架构。目前,易探云推出免备案香港物理机服务器性价比很高,E3-1230 8 核*1/16G DDR3/SATA 1TB/香港BGP线路/20Mbps/不限流量,仅...

物语云-VPS-美国洛杉矶VPS无限流量云windows大带宽100M不限流量 26/月起

物语云计算怎么样?物语云计算(MonogatariCloud)是一家成立于2016年的老牌国人商家,主营国内游戏高防独服业务,拥有多家机房资源,产品质量过硬,颇有一定口碑。本次带来的是特惠活动为美国洛杉矶Cera机房的不限流量大带宽VPS,去程直连回程4837,支持免费安装Windows系统。值得注意的是,物语云采用的虚拟化技术为Hyper-v,因此并不会超售超开。一、物语云官网点击此处进入物语云...

java小游戏源代码为你推荐
大学生就业形势分析如何正确认识大学生的就业形势sdfsdfsdfsdf世界上最大的一块金砖有多重?java程序员招聘女java程序员好找工作嘛za是哪个国家的IE是哪个国家的缩写erp系统教程在一个公司里怎样去学ERP东兴证券网站东兴证券超强版下载,东兴证券超强版v6下载官方网站,东兴证券软件下载在线沟通有效沟通的六个要点短信套餐移动有什么短信包月套餐,怎么开通?flex是什么Adobe 软件系列有那些,分别是做什么的?pass是什么锒行卡上的闪付pass是什么意思?
中文域名申请 最便宜虚拟主机 域名抢注工具 韩国空间 ubuntu更新源 太原联通测速平台 howfile web服务器的架设 免费个人空间 cdn联盟 泉州移动 域名和空间 t云 免费私人服务器 空间登陆首页 阿里云官方网站 独立主机 贵阳电信测速 开心online 建站行业 更多