Commit addd6759 authored by Jonathan Sudibya's avatar Jonathan Sudibya
Browse files

milestone server #1

parent 0e83946a
......@@ -69,7 +69,7 @@ jnlp.signed=false
jnlp.signing=
jnlp.signing.alias=
jnlp.signing.keystore=
main.class=TCPClient
main.class=client.Login
# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
manifest.custom.codebase=
# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package client;
/**
*
* @author Fauzan Hilmi
*/
public class ClientHandler {
public static void Login(String username, String password) {
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Connection;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/**
*
* @author Jonathan
*/
public class Listener implements Runnable {
private Socket connection;
private Vector<JSONObject> data;
private Thread t;
private boolean active;
public Listener(Socket _connection)
{
connection = _connection;
data = new Vector<>();
active = true;
}
@Override
public void run() {
JSONParser parser = new JSONParser();
while (active){
try {
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(connection.getInputStream()));
data.add((JSONObject) parser.parse(inFromServer.readLine()));
} catch (IOException ex) {
Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParseException ex) {
Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void start(){
if (t != null){
t = new Thread(this,"Client Listener");
t.start();
}
}
public void setActive(boolean _active)
{
active = _active;
}
public boolean isDataEmpty()
{
return data.isEmpty();
}
public JSONObject getFirstData()
{
return data.remove(0);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Connection;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.nio.charset.Charset;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.JSONObject;
/**
*
* @author Jonathan
*/
public class Sender implements Runnable {
private JSONObject data;
private Socket connectionSocket;
private boolean active;
private Thread t;
public Sender(Socket _connection)
{
connectionSocket = _connection;
active = true;
}
@Override
public void run()
{
while(active)
{
if (!data.isEmpty()){
try {
DataOutputStream outToServer = new DataOutputStream(connectionSocket.getOutputStream());
outToServer.write(data.toJSONString().getBytes(Charset.forName("UTF-8")));
data.clear();
} catch (IOException ex) {
Logger.getLogger(Sender.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public void setActive(boolean a)
{
active = a;
}
public void setData(JSONObject _data)
{
data = _data;
}
public boolean isDataEmpty()
{
return data.isEmpty();
}
public void start()
{
if (t != null)
{
t = new Thread(this,"Client Sender");
t.start();
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="Background" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="Background" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="Background">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="99" green="ff" red="99" type="rgb"/>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" alignment="0" groupAlignment="0" max="-2" attributes="0">
<Component id="NamaField" pref="253" max="32767" attributes="0"/>
<Component id="TimeCurrent" max="32767" attributes="0"/>
</Group>
<Component id="Time" alignment="0" min="-2" pref="235" max="-2" attributes="0"/>
<Component id="CharPosition" alignment="0" min="-2" pref="94" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0">
<Component id="Inventory" min="-2" pref="51" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="Mix" min="-2" pref="51" max="-2" attributes="0"/>
</Group>
<Component id="Field" min="-2" pref="55" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="Tradebox" min="-2" pref="51" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="Offer" min="-2" pref="51" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="Find" min="-2" pref="51" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="Logout" min="-2" pref="51" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="34" max="-2" attributes="0"/>
<Component id="Char" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="Move" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="xfield" min="-2" pref="21" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="yfield" min="-2" pref="21" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="34" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="42" max="-2" attributes="0"/>
<Component id="Canvas" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" attributes="0">
<Component id="NamaField" min="-2" pref="30" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="CharPosition" min="-2" pref="30" max="-2" attributes="0"/>
</Group>
<Component id="Char" alignment="1" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="Logout" min="-2" pref="47" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="13" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="xfield" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="yfield" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="Move" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="TimeCurrent" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="Time" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="Inventory" alignment="1" min="-2" pref="47" max="-2" attributes="0"/>
<Component id="Mix" alignment="1" min="-2" pref="47" max="-2" attributes="0"/>
<Component id="Tradebox" alignment="1" min="-2" pref="47" max="-2" attributes="0"/>
<Component id="Offer" alignment="1" min="-2" pref="47" max="-2" attributes="0"/>
<Component id="Find" alignment="1" min="-2" pref="47" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<Component id="Field" min="-2" pref="47" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="Canvas" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="58" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="NamaField">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Kalinga" size="18" style="1"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="66" red="66" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Nama Field"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="Char">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/client/image/charsteadygif.gif"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="Move">
<Properties>
<Property name="text" type="java.lang.String" value="Move To"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="MoveActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="Field">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/client/image/field.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="field"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="FieldActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="Inventory">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/client/image/inventory.gif"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="inventory"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="InventoryActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="Mix">
<Properties>
<Property name="text" type="java.lang.String" value="Mix"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="MixActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="Tradebox">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/client/image/trade.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="trade"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="TradeboxActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="Find">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/client/image/zoom.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="find"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="FindActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="Offer">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/client/image/offer.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="offer"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="OfferActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="Time">
<Properties>
<Property name="text" type="java.lang.String" value="Time"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="TimeCurrent">
<Properties>
<Property name="text" type="java.lang.String" value="Time Current"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="CharPosition">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Kalinga" size="18" style="1"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="66" red="66" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Position"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="xfield">
<Properties>
<Property name="text" type="java.lang.String" value="0"/>
<Property name="toolTipText" type="java.lang.String" value="posisi x"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="yfield">
<Properties>
<Property name="text" type="java.lang.String" value="0"/>
<Property name="toolTipText" type="java.lang.String" value="posisi y"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="Canvas">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="655" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="513" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Component class="javax.swing.JButton" name="Logout">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/client/image/logout.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Logout"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="LogoutActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/**
*
* @author Muhammad Husain
*/
public class Field extends javax.swing.JFrame {
/**
* Creates new form Field
*/
private Map maps;
private Invent invent;
private mixpanel mixp;
private findpanel findp;
private OfferPanel offerp;
private TradePanel tradebx;
private ItemTrade Itemt;
private int x, y;
private long waktupindah;
private JSONObject mapjson, userJSON, inventoryJSON;
private SimpleDateFormat sdf;
private Date tmove;
private String Message;
private TCPClient connector;
public Field(JSONObject _map, JSONObject _user, JSONObject _inv) {
mapjson = new JSONObject();mapjson = _map;
userJSON = new JSONObject();userJSON = _user;
inventoryJSON = new JSONObject();inventoryJSON = _inv;
setMAP();
initComponents();
initBuffer();
setTime();
}
private void setMAP(){
mapjson.put("x", userJSON.get("x"));
mapjson.put("y", userJSON.get("y"));
}
private void setTime(){
Timer t;
waktupindah = Long.parseLong(userJSON.get("time").toString());
sdf = new SimpleDateFormat("dd-MM-YYYY HH:mm:ss");
t = new Timer(1000, new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
TimeCurrent.setText("current time: " + sdf.format(new java.util.Date()));
}
});
t.start();
tmove = new Date(waktupindah);
Time.setText("moved time: " + sdf.format(tmove));
}
private void initBuffer(){
String user = (String) userJSON.get("token");
maps = new Map(mapjson);
Canvas.add(maps);
invent = new Invent();
mixp = new mixpanel();
findp = new findpanel();
offerp = new OfferPanel();
tradebx = new TradePanel(user);
Itemt = new ItemTrade();
NamaField.setText(mapjson.get("name").toString());
CharPosition.setText("Pos : " +userJSON.get("x")+" , "+userJSON.get("y"));
connector = new TCPClient();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
Background = new javax.swing.JPanel();
NamaField = new javax.swing.JLabel();
Char = new javax.swing.JLabel();
Move = new javax.swing.JButton();
Field = new javax.swing.JButton();
Inventory = new javax.swing.JButton();
Mix = new javax.swing.JButton();
Tradebox = new javax.swing.JButton();
Find = new javax.swing.JButton();
Offer = new javax.swing.JButton();
Time = new javax.swing.JLabel();
TimeCurrent = new javax.swing.JLabel();
CharPosition = new javax.swing.JLabel();