通过LAN网络(java)发送和收听摇摆事件? [英] Send and listen to swing events through LAN network (java)?

查看:76
本文介绍了通过LAN网络(java)发送和收听摇摆事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个带有GUI的简单聊天服务器和一个带有GUI的简单聊天客户端.我可以在本地网络中的一台计算机上打开服务器,并在另一台计算机上打开客户端.客户端用户键入服务器主机的地址并开始聊天. 我还用GUI编写了井字游戏.

I wrote a simple chat server with GUI and a simple chat client with GUI. I can open the server in one computer and the client in another computer within the local network. the client user type the address of the server host computer and start chatting. I also wrote a Tic Tac Toe game with GUI.

现在,我想将游戏嵌入到服务器-客户端程序中.我不知道如何/从哪里开始. (嵌入本身不是问题,问题在于如何使其通过网络工作)

Now I want to embed the game into the server-client program. I have no idea how/where to start. (the embedding itself is not the problem, the problem is how to make it work through a network)

井字游戏仅在JFrame中包含的JPanel中,将JPanel设置为GridLayout(3,3),并且将9个JButton添加到JPanel中.我编写了使游戏正常运行所需的所有代码.

The Tic tac toe game is simply in a JPanel contained in a JFrame, the JPanel is set to GridLayout(3, 3), and 9 JButtons added to the JPanel. I wrote all the necessary coding to make the game work.

因此,基本的问题是如何在客户端和服务器之间传递摇摆事件

So the basic Question is how to make swing events transfer between client and server

  • 当用户"A"选择游戏->井字游戏"时,向用户"B"发送有关开始游戏"并启动游戏框架的请求.

关键部分:

  • 当用户'A'单击JButton(在游戏中)时,相应的事件已发送给用户'B',因此两个GUI端都是相同的. ("A"和"B"看到相同的GUI更改.)
  • When user 'A' clicks on a JButton (in the game), the corresponding event sent to user 'B' so that both GUI ends are identical. ('A' and 'B' see the same GUI changes).

如何开始? 需要些什么? 有提示吗?

How to start? What are the required things? Any hints?

谢谢

推荐答案

我相信,您已经定义了一个用于完成服务器/客户端交互的接口.定义一种发送和发送邮件的方法接收消息.您的JButton单击仅需要确定单击/移动了哪个Tile,并通过与服务器/客户端的接口提供该信息.通过Swing事件不是一个好主意.

I believe, you have defined an interface over which your server/client interactions are done. Define a method using which you can send & receive the messages. Your JButton clicks just have to identify which Tile is clicked/moved and give that information over interface to server/client. Passing the Swing events are not good idea.

这篇关于通过LAN网络(java)发送和收听摇摆事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆