本文整理匯總了Java中com.esotericsoftware.kryonet.Listener類的典型用法代碼示例。如果您正苦於以下問題:Java Listener類的具體用法?Java Listener怎麽用?Java Listener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Listener類屬於com.esotericsoftware.kryonet包,在下文中一共展示了Listener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: LoginScreen
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
public LoginScreen(CatanGame pGame) {
aGame = pGame;
listener = new Listener() {
@Override
public void received(Connection connection, Object object) {
if (object instanceof LoginResponse) {
Gdx.app.postRunnable(() -> {
// Handle the login response from the server
if (((LoginResponse) object).success) {
// Cache the account used to login successfully
AccountManager.writeLocalAccount(account);
CatanGame.account = account;
// Move on to the main screen
aGame.switchScreen(ScreenKind.MAIN_MENU);
} else {
errorMessageLabel.setText(ERROR_USERNAME);
}
});
}
}
};
}
示例2: show
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
@Override
public void show() {
super.show();
entities = new HashMap<Integer, EntityPacket.EntityRender>();
game.getClient().sendTCP(new ViewShare("696969"));
game.getClient().addListener(new Listener() {
@Override
public void received(Connection connection, Object o) {
if(o instanceof EntityPacket)
Gdx.app.log("Entities", "Session" + ((EntityPacket) o).session);
}
});
}
示例3: addReceiver
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
/**
* Makes this chat client process and respond to audio sent from the server. If this message is not called, you will not hear anything
* from the server!
* @param client The client that audio data will be sent to from the server. Just use the normal client.
*/
public void addReceiver(Client client){
if(this.player == null)
this.createPlayer();
client.addListener(new Listener(){
public void received(Connection connection, Object object) {
// Only read objects of the correct type.
if(object instanceof VoiceNetData){
// Read data
VoiceNetData message = (VoiceNetData)object;
short[] data = message.getData();
// Play audio
processAudio(data, connection, message);
}
}
});
}
示例4: ClientController
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
public ClientController(AbstractDiagramController pDiagramController, String pServerIp, int pPort) {
diagramController = pDiagramController;
serverIp = pServerIp;
port = pPort;
client = new Client();
initKryo(client.getKryo());
client.addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof AbstractNode) {
Platform.runLater(() -> diagramController.createNodeView((AbstractNode)object, true));
} else if (object instanceof AbstractEdge) {
Platform.runLater(() -> diagramController.addEdgeView((AbstractEdge)object, true));
} else if (object instanceof Graph){
Graph graph = (Graph) object;
graph.addRemotePropertyChangeListener(ClientController.this);
Platform.runLater(() -> diagramController.load(graph, true));
} else if (object instanceof String[]){
Platform.runLater(() -> diagramController.remoteCommand((String[])object));
}
}
});
}
示例5: connect
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
public boolean connect(NetworkServerConfig config) {
try {
this.client.connect(5000, config.getAddress(), config.getTcpPort(), config.getUdpPort());
this.client.addListener(new Listener() {
public void received(Connection connection, Object object) {
if (object instanceof MessageModel) {
MessageModel response = (MessageModel) object;
masterTask.sendTask(TaskFactory.createTask(EnumTargetTask.MESSAGE_SERVER, EnumTargetTask.GAME, response));
}
}
});
this.masterTask.sendTask(TaskFactory.createTask(EnumTargetTask.MESSAGE_SERVER, EnumTargetTask.ACCOUNT, EnumWindow.INTERFACE));
return true;
} catch (IOException e) {
System.err.println("ERROR: " + e.getMessage());
e.printStackTrace();
return false;
}
}
示例6: NetworkServerImpl
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
public NetworkServerImpl(final NetworkConfigurationData configuration) {
Validate.notNull(configuration);
this.configuration = configuration;
ObjectSpace _objectSpace = new ObjectSpace();
this.objectSpace = _objectSpace;
MyServer _myServer = new MyServer(this.objectSpace);
this.server = _myServer;
Kryo _kryo = this.server.getKryo();
ObjectSpace.registerClasses(_kryo);
Kryo _kryo_1 = this.server.getKryo();
SerializerHelper.initializeKryo(_kryo_1);
this.sentBytes = 0L;
long _currentTimeMillis = System.currentTimeMillis();
this.lastLog = _currentTimeMillis;
MyHashMap<Integer, NetworkService> _myHashMap = new MyHashMap<Integer, NetworkService>();
this.serviceMap = _myHashMap;
HashSet<Listener> _newHashSet = CollectionLiterals.<Listener>newHashSet();
this.listeners = _newHashSet;
}
示例7: getEventsForPeriod
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
public void getEventsForPeriod(LocalDate from, LocalDate to, ObservableList<Event> observableEvents) {
EventMessage eventMessage = new EventMessage(currentUser.getValue(), EventMessage.Command.SEND_EVENTS, from, to);
CalendarClient client = CalendarClient.getInstance();
Listener listener = new Listener() {
public void received(Connection connection, Object object) {
if (object instanceof EventMessage) {
EventMessage message = (EventMessage) object;
if (message.getCommand() == EventMessage.Command.RECEIVE_EVENTS) {
observableEvents.addAll(message.getEvents());
client.removeListener(this);
}
}
}
};
client.addListener(listener);
client.sendMessage(eventMessage);
}
示例8: getAllTeams
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
private void getAllTeams() {
TeamMessage message = new TeamMessage(TeamMessage.Command.SEND_TEAMS);
CalendarClient client = CalendarClient.getInstance();
Listener getTeamsListener = new Listener() {
public void received(Connection connection, Object object) {
if (object instanceof TeamMessage) {
TeamMessage complete = (TeamMessage) object;
switch (complete.getCommand()) {
case RECEIVE_TEAMS:
setAllTeams(complete.getTeams());
break;
case SEND_TEAMS:
break;
}
client.removeListener(this);
}
}
};
client.addListener(getTeamsListener);
client.sendMessage(message);
}
示例9: getInvited
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
private void getInvited(int id) {
RequestMessage message = new RequestMessage(RequestMessage.Command.INVITED_USERS_REQUEST, id);
CalendarClient client = CalendarClient.getInstance();
Listener getInvitedListener = new Listener() {
public void received(Connection connection, Object object) {
if (object instanceof ParticipantUserMessage) {
ParticipantUserMessage complete = (ParticipantUserMessage) object;
switch (complete.getCommand()) {
case RECEIVE_ALL:
setInvited(complete.getParticipantUsers());
break;
case SEND_ALL:
break;
}
client.removeListener(this);
}
}
};
client.addListener(getInvitedListener);
client.sendMessage(message);
}
示例10: findUsers
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
public void findUsers() {
UserMessage userMessage = new UserMessage(UserMessage.Command.SEND_ALL);
CalendarClient client = CalendarClient.getInstance();
Listener listener = new Listener() {
public void received(Connection connection, Object object) {
if (object instanceof UserMessage) {
UserMessage message = (UserMessage) object;
if (message.getCommand() == UserMessage.Command.RECEIVE_ALL) {
users.addAll(message.getUsers());
allUsers.addAll(message.getUsers());
client.removeListener(this);
}
}
}
};
client.addListener(listener);
client.sendMessage(userMessage);
}
示例11: listenForNotifications
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
private void listenForNotifications() {
NotificationMessage findNotifications = new NotificationMessage(
NotificationMessage.Command.GETALL_NOTIFICATIONS);
CalendarClient client = CalendarClient.getInstance();
Listener listener = new Listener() {
public void received(Connection connection, Object object) {
if (object instanceof NotificationMessage) {
NotificationMessage message = (NotificationMessage) object;
switch (message.getCommand()) {
case RECEIVE_NOTIFICATION:
Platform.runLater(() -> notifications.addAll(0, message.getNotifications()));
break;
}
}
}
};
client.addListener(listener);
client.sendMessage(findNotifications);
}
示例12: FSUIPCKryonetInterface
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
public FSUIPCKryonetInterface(String server, int port) {
this.server = server;
this.port = port;
// ~
client = new Client();
client.start();
client.addListener(new Listener() {
public void received (Connection connection, Object object) {
if(object instanceof String) {
String message = (String)object;
if(message.startsWith("CHANGED")) {
Collection<OffsetItem> offsetItems = toOffsetItems(message);
for(OffsetItem offsetItem : offsetItems) {
offsetEventListeners.fire().valueChanged(offsetItem);
}
offsetCollectionEventListeners.fire().valuesChanged(offsetItems);
}
}
}
});
// ~
offsetEventListeners = EventListenerSupport.create(OffsetEventListener.class);
offsetCollectionEventListeners = EventListenerSupport.create(OffsetCollectionEventListener.class);
}
示例13: startLobby
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
private String[] startLobby(){
final Menu menu = new Menu("lobby");
client.getClient().addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof Network.Start) {
menu.action = "continue";
return;
}
}
});
client.sendReady();
String[] menuReturn;
do {
menuReturn = menu.render();
if(menuReturn[0].equals("forceStart")){
client.sendForceStart();
client.sendReady();
}
}while (!menuReturn[0].equals("continue"));
return menuReturn;
}
示例14: create
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
@Override
public void create() {
try{
if(true){
// Run server
this.server = new Server(22050, 22050);
server.bind(7777, 7777);
server.start();
relay = new VoiceChatServer(server.getKryo());
server.addListener(new Listener(){
public void received(Connection connection, Object object) {
relay.relayVoice(connection, object, server);
}
});
}
this.client = new Client(22050, 22050);
client.start();
client.connect(5000, "localhost", 7777, 7777);
this.sender = new VoiceChatClient(client.getKryo());
this.sender.addReceiver(client);
}catch(Exception e){
e.printStackTrace();
Gdx.app.exit();
}
// Other stuff for test
batch = new SpriteBatch();
font = new BitmapFont();
}
示例15: ClientController
import com.esotericsoftware.kryonet.Listener; //導入依賴的package包/類
public ClientController(AbstractDiagramController pDiagramController, String pServerIp, int pPort) {
diagramController = pDiagramController;
serverIp = pServerIp;
port = pPort;
client = new Client();
initKryo(client.getKryo());
client.addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof AbstractNode) {
Platform.runLater(() -> diagramController.createNodeView((AbstractNode)object, true));
}
else if (object instanceof AbstractEdge) {
Platform.runLater(() -> diagramController.addEdgeView((AbstractEdge)object, true));
}
else if (object instanceof Graph){
Graph graph = (Graph) object;
graph.addRemotePropertyChangeListener(ClientController.this);
Platform.runLater(() -> diagramController.load(graph, true));
}
else if (object instanceof String[]){
Platform.runLater(() -> diagramController.remoteCommand((String[])object));
}
}
});
}