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!

PQ.hosting全线9折,1Gbps带宽不限流量VPS/€3/月,全球11大机房可选

Hostadvice主机目录对我们的服务进行了测试,然后给PQ.hosting颁发了十大WordPress托管奖。为此,宣布PQ.Hosting将在一周内进行折扣优惠,购买和续订虚拟服务器使用优惠码:Hostadvice ,全部优惠10%。PQ.hosting,国外商家,成天于2019年,正规公司,是全球互联网注册商协会 RIPE 的成员。主要是因为提供1Gbps带宽、不限流量的基于KVM虚拟的V...

数脉科技:香港服务器低至350元/月;阿里云CN2+BGP线路,带宽10M30M50M100M

数脉科技(shuhost)8月促销:香港独立服务器,自营BGP、CN2+BGP、阿里云线路,新客立减400港币/月,老用户按照优惠码减免!香港服务器带宽可选10Mbps、30Mbps、50Mbps、100Mbps带宽,支持中文本Windows、Linux等系统。数脉香港特价阿里云10MbpsCN2,e3-1230v2,16G内存,1T HDD 或 240G SSD,10Mbps带宽,IPv41个,...

菠萝云:带宽广州移动大带宽云广州云:广州移动8折优惠,月付39元

菠萝云国人商家,今天分享一下菠萝云的广州移动机房的套餐,广州移动机房分为NAT套餐和VDS套餐,NAT就是只给端口,共享IP,VDS有自己的独立IP,可做站,商家给的带宽起步为200M,最高给到800M,目前有一个8折的优惠,另外VDS有一个下单立减100元的活动,有需要的朋友可以看看。菠萝云优惠套餐:广州移动NAT套餐,开放100个TCP+UDP固定端口,共享IP,8折优惠码:gzydnat-8...

java小游戏源代码为你推荐
贸易配额进出口配额是怎么回事情?ata考试有人能仔细讲一下ATA考试是什么吗?sdfsdfsdfsdf小米手机投诉热线webservice框架如何用webservice 的cxf框架cursorlocation如何用ENVI把不同图像中的相同地点的某个像素点的值读出来。按时间把这个点的值连起来,。谢谢好人。怎样删除聊天记录自己已发出的微信聊天记录怎样删除才不会让对方看见空间导航QQ空间中如何自定义导航?网页背景音乐代码有没有网页背景音乐播放器代码??455端口135端口,139,455~~~~managedquery如何使用volley进行同步请求
美国虚拟主机 广西虚拟主机 哈尔滨服务器租用 域名服务器是什么 域名备案网站 siteground winhost 网站被封 牛人与腾讯客服对话 好看qq空间 台湾谷歌地址 佛山高防服务器 isp服务商 爱奇艺vip免费试用7天 双线机房 英国伦敦 登陆qq空间 创速 免费获得q币 .htaccess 更多