Commit 2e2ad538 authored by Darwin's avatar Darwin
Browse files

inventory done

parents 4e734d01 a0655911
src/server/nbproject/private/
src/server/build/
src/server/nbproject/private/private.properties
src/server/nbproject/private/private.xml
src/server/build/classes/
src/server/build/classes/tcpserver/
src/server/nbbuild/
src/server/dist/
src/server/nbdist/
src/server/nbactions.xml
src/server/nb-configuration.xml
src/client/nbproject/private/
src/client/nbproject/private/private.properties
src/client/nbproject/private/private.xml
src/client/build/
src/client/nbbuild/
src/client/dist/
src/client/nbdist/
src/client/nbactions.xml
src/client/nb-configuration.xml
......
#Fri, 17 Apr 2015 10:50:27 +0700
C\:\\Users\\Stephen\\Documents\\NetBeansProjects\\TubesSister\\src\\client=
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="Login/Register"/>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="cc" red="99" type="rgb"/>
</Property>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
</Property>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="FISHfingers" size="10" style="0"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="99" red="99" type="rgb"/>
</Property>
<Property name="locationByPlatform" type="boolean" value="true"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[400, 300]"/>
</Property>
<Property name="name" type="java.lang.String" value="loginFrame" noResource="true"/>
<Property name="resizable" type="boolean" value="false"/>
</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">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="70" pref="70" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="loginLabel" min="-2" max="-2" attributes="0"/>
<Component id="registerLabel" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" attributes="0">
<EmptySpace min="90" pref="90" max="-2" attributes="0"/>
<Component id="usernameLabel" min="-2" pref="70" max="-2" attributes="0"/>
<EmptySpace min="37" pref="37" max="-2" attributes="0"/>
<Component id="usernameTextField" min="-2" pref="128" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<EmptySpace min="90" pref="90" max="-2" attributes="0"/>
<Component id="passwordLabel" min="-2" pref="70" max="-2" attributes="0"/>
<EmptySpace min="37" pref="37" max="-2" attributes="0"/>
<Component id="passwordTextField" min="-2" pref="128" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<EmptySpace min="150" pref="150" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="registerButton" min="-2" pref="77" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="70" pref="70" max="-2" attributes="0"/>
<Component id="registernowLabel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<EmptySpace min="80" pref="80" max="-2" attributes="0"/>
<Component id="loginButton" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="messageLabel" min="-2" pref="382" max="-2" attributes="0"/>
<EmptySpace pref="67" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="serverLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="serverTextField" min="-2" pref="135" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="backLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="serverLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="serverTextField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="backLabel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="messageLabel" min="-2" pref="20" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="loginLabel" min="-2" max="-2" attributes="0"/>
<Component id="registerLabel" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="17" pref="17" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="6" pref="6" max="-2" attributes="0"/>
<Component id="usernameLabel" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="usernameTextField" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="18" pref="18" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="8" pref="8" max="-2" attributes="0"/>
<Component id="passwordLabel" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="passwordTextField" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="16" pref="16" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="registerButton" min="-2" max="-2" attributes="0"/>
<Component id="registernowLabel" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="20" pref="20" max="-2" attributes="0"/>
<Component id="loginButton" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="loginLabel">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="LOGIN"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="registerLabel">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="REGISTER"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="usernameLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Username"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="passwordLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Password"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="usernameTextField">
</Component>
<Component class="javax.swing.JTextField" name="passwordTextField">
</Component>
<Component class="javax.swing.JLabel" name="registernowLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Register Now!"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="registernowLabelMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="loginButton">
<Properties>
<Property name="text" type="java.lang.String" value="Login"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loginButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="registerButton">
<Properties>
<Property name="text" type="java.lang.String" value="Register"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="registerButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="messageLabel">
</Component>
<Component class="javax.swing.JTextField" name="serverTextField">
<Properties>
<Property name="text" type="java.lang.String" value="localhost"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="serverLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Server:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="backLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Back"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="backLabelMouseClicked"/>
</Events>
</Component>
</SubComponents>
</Form>
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "TCPClient.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.
......@@ -117,6 +117,19 @@ public class TCPClient {
return obj;
}
public JSONObject fieldJSON(String token) {
JSONObject obj = new JSONObject();
try {
obj.put("method", "field");
obj.put("token", token);
} catch(Exception e) {
e.printStackTrace();
}
return obj;
}
public JSONObject offerJSON(String token, int offered_item, int n1, int demanded_item, int n2) {
JSONObject obj = new JSONObject();
......@@ -294,127 +307,150 @@ public class TCPClient {
return responseJSON;
}
public static void main(String argv[]) throws Exception
public JSONObject field(String token) throws Exception
{
TCPClient client = new TCPClient("localhost", 6789);
// do {
// BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
// DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
// BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
//
// // Test Register
// do {
// System.out.println("Register");
// System.out.print("Username : "); username = inFromUser.readLine();
// System.out.print("Password : "); password = inFromUser.readLine();
// String toSend = registerJSON(username, password).toString();
//
// outToServer.writeBytes(toSend + '\n');
//
// String response = inFromServer.readLine();
// JSONObject responseJSON = new JSONObject(response);
// responseStatus = responseJSON.getString("status");
// if(responseStatus.equalsIgnoreCase("ok")) {
// System.out.println("Registration Success!");
// } else if(responseStatus.equalsIgnoreCase("fail")) {
// String reason = responseJSON.getString("description");
// System.out.println("Registration fail, " + reason);
// }
// System.out.println();
// } while(!responseStatus.equalsIgnoreCase("ok"));
//
// // Test Login
// do {
// System.out.println("Login");
// System.out.print("Username : "); username = inFromUser.readLine();
// System.out.print("Password : "); password = inFromUser.readLine();
// String toSend = loginJSON(username, password).toString();
//
// outToServer.writeBytes(toSend + '\n');
//
// String response = inFromServer.readLine();
// JSONObject responseJSON = new JSONObject(response);
// responseStatus = responseJSON.getString("status");
// if(responseStatus.equalsIgnoreCase("ok")) {
// System.out.println("Login Success!");
// System.out.println("Token : " + responseJSON.getString("token"));
// token = responseJSON.getString("token");
// } else if(responseStatus.equalsIgnoreCase("fail")) {
// String reason = responseJSON.getString("description");
// System.out.println("Login fail, " + reason);
// }
// System.out.println();
// } while(!responseStatus.equalsIgnoreCase("ok"));
//
// // Test Inventory
// do {
// do {
// System.out.print("Command : "); command = inFromUser.readLine();
// } while(!command.equalsIgnoreCase("inventory") && !command.equalsIgnoreCase("exit"));
//
// if(command.equalsIgnoreCase("inventory")) {
// String toSend = inventoryJSON(token).toString();
//
// outToServer.writeBytes(toSend + '\n');
//
// String response = inFromServer.readLine();
// JSONObject responseJSON = new JSONObject(response);
// responseStatus = responseJSON.getString("status");
// if(responseStatus.equalsIgnoreCase("ok")) {
// System.out.println("Your Inventory : ");
// List inventory = new ArrayList<Integer>();
// JSONArray jsonarray = responseJSON.getJSONArray("inventory");
// for(int i=0; i<jsonarray.length(); i++) {
// inventory.add(jsonarray.getInt(i));
// }
// printItemList(inventory);
// } else if(responseStatus.equalsIgnoreCase("error")) {
// System.out.println("Error opening inventory");
// }
// System.out.println();
// }
// } while(!command.equalsIgnoreCase("exit"));
//
// // Test Mix Item
// do {
// System.out.println("Mix Item");
// System.out.print("Item 1 ID : "); int id1 = Integer.parseInt(inFromUser.readLine());
// System.out.print("Item 2 ID : "); int id2 = Integer.parseInt(inFromUser.readLine());
// String toSend = mixitemJSON(token, id1, id2).toString();
//
// outToServer.writeBytes(toSend + '\n');
//
// String response = inFromServer.readLine();
// JSONObject responseJSON = new JSONObject(response);
// responseStatus = responseJSON.getString("status");
// if(responseStatus.equalsIgnoreCase("ok")) {
// System.out.println("Mix item succeded, your new item id : " + responseJSON.getInt("item"));
// } else if(responseStatus.equalsIgnoreCase("fail")) {
// System.out.println("Failed to mix item, " + responseJSON.getString("description"));
// } else if(responseStatus.equalsIgnoreCase("error")) {
// System.out.println("Error mixing item");
// }
// System.out.println();
// } while(true);
// } while(!command.equalsIgnoreCase("exit"));
JSONObject response = client.login("ayam", "ayam");
if(response.getString("status").equals("ok")) {
client.token = response.getString("token");
client.x=response.getInt("x");
client.y=response.getInt("y");
System.out.println("Field");
String toSend = fieldJSON(token).toString();
//throw ioexception
DataOutputStream outToServer;
try {
outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes(toSend + '\n');
} catch (IOException ex) {
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
throw new Exception("outtoserver move exception");
}
System.out.println(response.toString());
response = client.map(client.token);
System.out.println(response.toString());
//ambil balasan server
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String response = inFromServer.readLine();
JSONObject responseJSON = new JSONObject(response);
response = client.offer(client.token, 0, 1, 7, 3);
System.out.println(response.toString());
return responseJSON;
}
// public static void main(String argv[]) throws Exception
// {
// TCPClient client = new TCPClient("localhost", 6789);
//
//// do {
//// BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
//// DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
//// BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
////
//// // Test Register
//// do {
//// System.out.println("Register");
//// System.out.print("Username : "); username = inFromUser.readLine();
//// System.out.print("Password : "); password = inFromUser.readLine();
//// String toSend = registerJSON(username, password).toString();
////
//// outToServer.writeBytes(toSend + '\n');
////
//// String response = inFromServer.readLine();
//// JSONObject responseJSON = new JSONObject(response);
//// responseStatus = responseJSON.getString("status");
//// if(responseStatus.equalsIgnoreCase("ok")) {
//// System.out.println("Registration Success!");
//// } else if(responseStatus.equalsIgnoreCase("fail")) {
//// String reason = responseJSON.getString("description");
//// System.out.println("Registration fail, " + reason);
//// }
//// System.out.println();
//// } while(!responseStatus.equalsIgnoreCase("ok"));
////
//// // Test Login
//// do {
//// System.out.println("Login");
//// System.out.print("Username : "); username = inFromUser.readLine();
//// System.out.print("Password : "); password = inFromUser.readLine();
//// String toSend = loginJSON(username, password).toString();
////
//// outToServer.writeBytes(toSend + '\n');
////
//// String response = inFromServer.readLine();
//// JSONObject responseJSON = new JSONObject(response);
//// responseStatus = responseJSON.getString("status");
//// if(responseStatus.equalsIgnoreCase("ok")) {
//// System.out.println("Login Success!");
//// System.out.println("Token : " + responseJSON.getString("token"));
//// token = responseJSON.getString("token");
//// } else if(responseStatus.equalsIgnoreCase("fail")) {
//// String reason = responseJSON.getString("description");
//// System.out.println("Login fail, " + reason);
//// }
//// System.out.println();
//// } while(!responseStatus.equalsIgnoreCase("ok"));
////
//// // Test Inventory
//// do {
//// do {
//// System.out.print("Command : "); command = inFromUser.readLine();
//// } while(!command.equalsIgnoreCase("inventory") && !command.equalsIgnoreCase("exit"));
////
//// if(command.equalsIgnoreCase("inventory")) {
//// String toSend = inventoryJSON(token).toString();
////
//// outToServer.writeBytes(toSend + '\n');
////
//// String response = inFromServer.readLine();
//// JSONObject responseJSON = new JSONObject(response);
//// responseStatus = responseJSON.getString("status");
//// if(responseStatus.equalsIgnoreCase("ok")) {
//// System.out.println("Your Inventory : ");
//// List inventory = new ArrayList<Integer>();
//// JSONArray jsonarray = responseJSON.getJSONArray("inventory");
//// for(int i=0; i<jsonarray.length(); i++) {
//// inventory.add(jsonarray.getInt(i));
//// }
//// printItemList(inventory);
//// } else if(responseStatus.equalsIgnoreCase("error")) {
//// System.out.println("Error opening inventory");
//// }
//// System.out.println();
//// }
//// } while(!command.equalsIgnoreCase("exit"));
////
//// // Test Mix Item
//// do {
//// System.out.println("Mix Item");
//// System.out.print("Item 1 ID : "); int id1 = Integer.parseInt(inFromUser.readLine());
//// System.out.print("Item 2 ID : "); int id2 = Integer.parseInt(inFromUser.readLine());
//// String toSend = mixitemJSON(token, id1, id2).toString();
////
//// outToServer.writeBytes(toSend + '\n');
////
//// String response = inFromServer.readLine();
//// JSONObject responseJSON = new JSONObject(response);
//// responseStatus = responseJSON.getString("status");
//// if(responseStatus.equalsIgnoreCase("ok")) {
//// System.out.println("Mix item succeded, your new item id : " + responseJSON.getInt("item"));
//// } else if(responseStatus.equalsIgnoreCase("fail")) {
//// System.out.println("Failed to mix item, " + responseJSON.getString("description"));
//// } else if(responseStatus.equalsIgnoreCase("error")) {
//// System.out.println("Error mixing item");
//// }
//// System.out.println();
//// } while(true);
//// } while(!command.equalsIgnoreCase("exit"));
//
// JSONObject response = client.login("ayam", "ayam");
// if(response.getString("status").equals("ok")) {
// client.token = response.getString("token");
// client.x=response.getInt("x");
// client.y=response.getInt("y");
// }
// System.out.println(response.toString());
//
// response = client.map(client.token);
// System.out.println(response.toString());
//
// response = client.field(client.token);
// System.out.println(response.toString());
//
// response = client.offer(client.token, 0, 1, 7, 3);
// System.out.println(response.toString());
// }
}
#Fri, 17 Apr 2015 11:38:04 +0700
C\:\\Users\\Stephen\\Documents\\NetBeansProjects\\TubesSister\\src\\server=
......@@ -260,6 +260,49 @@ public class MySQLAccess {