Commit 77faf0bf authored by Stephen's avatar Stephen
Browse files

Merged

parents 5c10e0f1 52eb16cb
src/server/nbproject/private/
src/server/nbproject/private/private.properties
src/server/nbproject/private/private.xml
src/server/build/
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/
......
#Fri, 17 Apr 2015 10:50:27 +0700
#Sun, 19 Apr 2015 10:31:41 +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>
......@@ -4,7 +4,7 @@
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/LoginPage.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/MainPage.java</file>
</group>
</open-files>
</project-private>
This diff is collapsed.
This diff is collapsed.
<?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">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</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 tcpclient;
/**
*
* @author susanti_2
*/
public class MenuPage extends javax.swing.JFrame {
/**
* Creates new form MenuPage
*/
public MenuPage() {
initComponents();
}
/**
* 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() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MenuPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MenuPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MenuPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MenuPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MenuPage().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}
......@@ -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,6 +307,29 @@ public class TCPClient {
return responseJSON;
}
public JSONObject field(String token) throws Exception
{
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");
}
//ambil balasan server
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String response = inFromServer.readLine();
JSONObject responseJSON = new JSONObject(response);
return responseJSON;
}
// public static void main(String argv[]) throws Exception
// {
......@@ -411,6 +447,9 @@ public class TCPClient {
// 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());
// }
......
......@@ -4,4 +4,6 @@ do.depend=false
do.jar=true
javac.debug=true
javadoc.preview=true
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
......@@ -260,6 +260,49 @@ public class MySQLAccess {
return response;
}
public JSONObject field(int userID) throws JSONException
{
open();
JSONObject response = new JSONObject();
try {
preparedStatement = connect.prepareStatement("SELECT position_x, position_y FROM user WHERE "
+ "id=" + userID + ";");
resultSet = preparedStatement.executeQuery();
if(resultSet.first()) {
int curr_x = resultSet.getInt("position_x");
int curr_y = resultSet.getInt("position_y");
//System.out.println("nih map :"+TCPServer.map[curr_x][curr_y]);
String id_other = TCPServer.map[curr_x][curr_y];
if(id_other.equalsIgnoreCase(""))
{
response.put("status", "fail");
response.put("description", "Item has been taken");
}
else //item belom diambil
{
preparedStatement = connect.prepareStatement("SELECT id_item FROM items WHERE "+ "id_other=\"" + id_other + "\";");
resultSet = preparedStatement.executeQuery();
if(resultSet.first()) {
int item_taken = resultSet.getInt("id_item");
//map dijadikan kosong
TCPServer.map[curr_x][curr_y] = "";
//kembalikan response
response.put("status", "ok");
response.put("item", item_taken);
}
}
}
} catch (SQLException e) {
response.put("status", "error");
e.printStackTrace();
}
close();
return response;
}
public JSONObject offer(int userID, int offered_item, int n1, int demanded_item, int n2) throws JSONException {
open();
JSONObject response = new JSONObject();
......
......@@ -13,9 +13,9 @@ public class TCPServer {
public String request;
public String token;
public int userID;
int width;
int height;
String[][] map;
public int width;
public int height;
public static String[][] map;
public TCPServer(int port) throws IOException {
System.out.println("Server running! Waiting for connection...");
......@@ -64,12 +64,12 @@ public class TCPServer {
if (f.exists()){
InputStream is = new FileInputStream("map.json");
String jsonTxt = CharStreams.toString(new InputStreamReader(is, "UTF-8"));
System.out.println(jsonTxt);
//System.out.println(jsonTxt);
JSONObject jsonObj = new JSONObject(jsonTxt);
String nama = jsonObj.getString("name");
width = jsonObj.getInt("width");
height = jsonObj.getInt("height");
String[][] map = new String[width][height];
map = new String[width][height];
JSONArray MAP = jsonObj.getJSONArray("map");
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++)
......@@ -102,6 +102,17 @@ public class TCPServer {
}
}
public JSONObject field(JSONObject clientObject) throws JSONException {
if(clientObject.getString("token").equalsIgnoreCase(token)) {
return sql.field(userID);
} else {
JSONObject responseJSON = new JSONObject();
responseJSON.put("status", "error");
return responseJSON;
}
}
public JSONObject offer(JSONObject clientObject) throws JSONException {
if(clientObject.getString("token").equalsIgnoreCase(token)) {
return sql.offer(userID,
......@@ -168,6 +179,10 @@ public class TCPServer {
JSONObject responseJSON = server.move(clientObject);
System.out.println(responseJSON.toString());
outToClient.writeBytes(responseJSON.toString() + "\n");
} else if(method.equalsIgnoreCase("field")) {
JSONObject responseJSON = server.field(clientObject);
System.out.println(responseJSON.toString());
outToClient.writeBytes(responseJSON.toString() + "\n");
} else if(method.equalsIgnoreCase("offer")) {
JSONObject responseJSON = server.offer(clientObject);
System.out.println(responseJSON.toString());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment