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!

AlphaVPS(€3.99/月)VPS年付15欧,AMD EYPC+NVMe系列起

AlphaVPS是一家保加利亚本土主机商(DA International Group Ltd),提供VPS主机及独立服务器租用等,数据中心包括美国(洛杉矶/纽约)、德国、英国和保加利亚等,公司办公地点跟他们提供的保加利亚数据中心在一栋楼内,自有硬件,提供IPv4+IPv6,支持PayPal或者信用卡等方式付款。商家提供的大硬盘VPS主机,提供128GB-2TB磁盘,最低年付15欧元起,也可以选择...

香港服务器多少钱一个月?香港云服务器最便宜价格

香港服务器多少钱一个月?香港服务器租用配置价格一个月多少,现在很多中小型企业在建站时都会租用香港服务器,租用香港服务器可以使网站访问更流畅、稳定性更好,安全性会更高等等。香港服务器的租用和其他地区的服务器租用配置元素都是一样的,那么为什么香港服务器那么受欢迎呢,香港云服务器最便宜价格多少钱一个月呢?阿里云轻量应用服务器最便宜的是1核1G峰值带宽30Mbps,24元/月,288元/年。不过我们一般选...

10gbiz首月半价月付2.36美元,香港/洛杉矶VPS、硅谷独立服务器/站群服务器

收到10gbiz发来的7月份优惠方案,中国香港、美国洛杉矶机房VPS主机4折优惠码,优惠后洛杉矶VPS月付2.36美元起,香港VPS月付2.75美元起。这是一家2020年成立的主机商,提供的产品包括独立服务器租用和VPS主机等,数据中心在美国洛杉矶、圣何塞和中国香港。商家VPS主机基于KVM架构,支持使用PayPal或者支付宝付款。洛杉矶VPS架构CPU内存硬盘带宽系统价格单核512MB10GB1...

java小游戏源代码为你推荐
scriptmanagerajax ToolkitScriptManager与ScriptManager的区别怎么用电脑发短信怎么样用电脑给手机发短信?5e5e5e计算器里5.55556e-5是什么意思netbios协议tcp/ip、ipx/spx、netbios这三个通信协议的区别sms是什么短信确认码是什么cursorlocationsession("rs").cursorlocation=3是什么意思?za是哪个国家的IE是哪个国家的缩写东兴证券网站东兴证券开户是假的吗?particular教程有没有制作花瓣飘落的AE教程微盟价格微盟怎么收费?
域名批量查询 西安服务器租用 xenvps 已经备案域名 金万维动态域名 greengeeks x3220 hostmaster 国外主机 免费主机 鲨鱼机 优惠码 wdcp 免费名片模板 灵动鬼影 有益网络 美国堪萨斯 电信虚拟主机 t云 Updog 更多