Chat Tutorial in NetBeans/Text Client: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>SimonSmall Added building the Text Client |
imported>SimonSmall small correction |
||
| Line 1: | Line 1: | ||
== Introduction == |
== Introduction == |
||
These instructions are a continuation of the Chat Tutorial. This is a text based |
These instructions are a continuation of the Chat Tutorial. This is a text based client that runs in a command / terminal window. |
||
client that runs in a command / terminal window. |
|||
== NetBeans Project == |
== NetBeans Project == |
||
In the NetBeans IDE, |
In the NetBeans IDE, close all open projects. Click New Project, choose Java and Java Application. Click Next, then give the Project Name as client. Change the Project Location to DEVPATH\DevChat (DEVPATH, see above); the Project Folder is shown as DEVPATH\DevChat\client with DEVPATH being your chosen location. Check that Create Main Class is ticked, and the class is client.Test before clicking Finish. |
||
The empty Project is created in NetBeans. Under the Files tab you will see the directory structure it has also generated; check this using your file explorer. |
The empty Project is created in NetBeans. Under the Files tab you will see the directory structure it has also generated; check this using your file explorer. |
||
| Line 14: | Line 13: | ||
=== Client Files === |
=== Client Files === |
||
The following files need to be created, as they are not present in the marauroa source file |
The following files need to be created, as they are not present in the marauroa source file. |
||
==== Client.java ==== |
==== Client.java ==== |
||
Right-click on the client package and add a new Class. Give the class name as Client. Add the following code: |
Right-click on the client package and add a new Java Class. Give the class name as Client. Add the following code: |
||
<source lang="Java"> |
<source lang="Java"> |
||
package client; |
package client; |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
import java.util.Map; |
import java.util.Map; |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
import marauroa.client.ClientFramework; |
import marauroa.client.ClientFramework; |
||
import marauroa.client.net.IPerceptionListener; |
import marauroa.client.net.IPerceptionListener; |
||
| Line 77: | Line 75: | ||
} |
} |
||
@Override |
|||
protected void onPerception(MessageS2CPerception message) { |
protected void onPerception(MessageS2CPerception message) { |
||
try { |
try { |
||
| Line 84: | Line 83: | ||
} |
} |
||
} |
} |
||
@Override |
|||
protected List<TransferContent> onTransferREQ(List<TransferContent> items) { |
protected List<TransferContent> onTransferREQ(List<TransferContent> items) { |
||
return items; |
return items; |
||
} |
} |
||
@Override |
|||
protected void onTransfer(List<TransferContent> items) { |
protected void onTransfer(List<TransferContent> items) { |
||
} |
} |
||
@Override |
|||
protected void onAvailableCharacters(String[] characters) { |
protected void onAvailableCharacters(String[] characters) { |
||
available_characters = characters; |
available_characters = characters; |
||
} |
} |
||
@Override |
|||
protected void onServerInfo(String[] info) { |
protected void onServerInfo(String[] info) { |
||
for (String s : info) { |
for (String s : info) { |
||
| Line 101: | Line 104: | ||
} |
} |
||
} |
} |
||
@Override |
|||
protected String getGameName() { |
protected String getGameName() { |
||
return "Chat"; |
return "Chat"; |
||
} |
} |
||
@Override |
|||
protected String getVersionNumber() { |
protected String getVersionNumber() { |
||
return "0.5"; |
return "0.5"; |
||
} |
} |
||
@Override |
|||
protected void onPreviousLogins(List<String> previousLogins) { |
protected void onPreviousLogins(List<String> previousLogins) { |
||
} |
} |
||
class PerceptionListener implements IPerceptionListener { |
class PerceptionListener implements IPerceptionListener { |
||
@Override |
|||
public boolean onAdded(RPObject object) { |
public boolean onAdded(RPObject object) { |
||
if (object.has("text")) { |
if (object.has("text")) { |
||
| Line 120: | Line 128: | ||
return false; |
return false; |
||
} |
} |
||
@Override |
|||
public boolean onModifiedAdded(RPObject object, RPObject changes) { |
public boolean onModifiedAdded(RPObject object, RPObject changes) { |
||
return false; |
return false; |
||
} |
} |
||
@Override |
|||
public boolean onModifiedDeleted(RPObject object, RPObject changes) { |
public boolean onModifiedDeleted(RPObject object, RPObject changes) { |
||
return false; |
return false; |
||
} |
} |
||
@Override |
|||
public boolean onDeleted(RPObject object) { |
public boolean onDeleted(RPObject object) { |
||
return false; |
return false; |
||
} |
} |
||
@Override |
|||
public boolean onMyRPObject(RPObject added, RPObject deleted) { |
public boolean onMyRPObject(RPObject added, RPObject deleted) { |
||
return false; |
return false; |
||
} |
} |
||
@Override |
|||
public void onSynced() { |
public void onSynced() { |
||
} |
} |
||
@Override |
|||
public void onUnsynced() { |
public void onUnsynced() { |
||
} |
} |
||
@Override |
|||
public void onException(Exception e, marauroa.common.net.message.MessageS2CPerception perception) { |
public void onException(Exception e, marauroa.common.net.message.MessageS2CPerception perception) { |
||
e.printStackTrace(); |
e.printStackTrace(); |
||
System.exit(-1); |
System.exit(-1); |
||
} |
} |
||
@Override |
|||
public boolean onClear() { |
public boolean onClear() { |
||
return false; |
return false; |
||
} |
} |
||
public void onPerceptionBegin(byte type, int timestamp) { |
public void onPerceptionBegin(byte type, int timestamp) { |
||
} |
} |
||
public void onPerceptionEnd(byte type, int timestamp) { |
public void onPerceptionEnd(byte type, int timestamp) { |
||
} |
} |
||