Commit 03005122 authored by Tegar Aji Pangestu's avatar Tegar Aji Pangestu
Browse files

First Commit Client

parent 954ac266
......@@ -169,16 +169,22 @@
<Component id="philoIcon" min="-2" pref="84" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="philoAmount" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="79" max="-2" attributes="0"/>
<Component id="firstParamIcon" min="-2" pref="81" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="gemsIcon" min="-2" pref="84" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="gemsAmount" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="87" max="32767" attributes="0"/>
<Component id="jButton2" min="-2" pref="62" max="-2" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="firstParamIcon" min="-2" pref="81" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="gemsIcon" min="-2" pref="84" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="gemsAmount" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="87" max="32767" attributes="0"/>
<Component id="jButton2" min="-2" pref="62" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="91" max="-2" attributes="0"/>
</Group>
</Group>
......
......@@ -12,6 +12,7 @@ import javax.swing.JOptionPane;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import thealchemist.controller.ConnectionControler;
import thealchemist.model.Avatar;
import thealchemist.model.Clay;
import thealchemist.model.Gem;
......@@ -43,10 +44,19 @@ public class FindWindow extends javax.swing.JFrame {
jSONObject.put("method", "inventory");
jSONObject.put("token", Avatar.token);
JOptionPane.showMessageDialog(rootPane, jSONObject.toString());
JSONObject response = new JSONObject();
response.put("inventory", new JSONArray(new Object[] {1,2,3,4,5,1,2,3,4,5}) );
response.put("status", "ok");
// Connection start
ConnectionControler connectionControler = new ConnectionControler(ConnectionControler.host, ConnectionControler.port);
connectionControler.sendMessage(jSONObject);
JOptionPane.showMessageDialog(rootPane, "Sent Message");
JSONObject response = connectionControler.receiveMessage();
JOptionPane.showMessageDialog(rootPane, response.toString());
connectionControler.closeConnection();
// Connection close
// JSONObject response = new JSONObject();
// response.put("inventory", new JSONArray(new Object[] {1,2,3,4,5,1,2,3,4,5}) );
// response.put("status", "ok");
// JOptionPane.showMessageDialog(rootPane, response.toString());
JSONArray jSONArray = response.getJSONArray("inventory");
Honey honey = new Honey();
honey.setAmount((int)jSONArray.get(0));
......@@ -364,15 +374,18 @@ public class FindWindow extends javax.swing.JFrame {
.addComponent(philoIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(philoAmount)
.addGap(79, 79, 79)
.addComponent(firstParamIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(gemsIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(gemsAmount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(firstParamIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(gemsIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(gemsAmount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(91, 91, 91))))
);
......
......@@ -12,7 +12,7 @@ import javax.swing.JOptionPane;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import sun.util.calendar.CalendarUtils;
import thealchemist.controller.ConnectionControler;
import thealchemist.model.Avatar;
import thealchemist.model.Clay;
import thealchemist.model.Gem;
......@@ -46,40 +46,52 @@ public class OfferWindow extends javax.swing.JFrame {
jSONObject.put("method", "inventory");
jSONObject.put("token", Avatar.token);
JOptionPane.showMessageDialog(rootPane, jSONObject.toString());
JSONObject response = new JSONObject();
response.put("inventory", new JSONArray(new Object[] {1,2,3,4,5,1,2,3,4,5}) );
response.put("status", "ok");
// Connection start
ConnectionControler connectionControler = new ConnectionControler(ConnectionControler.host, ConnectionControler.port);
connectionControler.sendMessage(jSONObject);
JOptionPane.showMessageDialog(rootPane, "Sent Message");
JSONObject response = connectionControler.receiveMessage();
JOptionPane.showMessageDialog(rootPane, response.toString());
JSONArray jSONArray = response.getJSONArray("inventory");
Honey honey = new Honey();
honey.setAmount((int)jSONArray.get(0));
honeyAmount.setText(String.valueOf(honey.getAmount()));
Herb herb = new Herb();
herb.setAmount((int)jSONArray.get(1));
herbsAmount.setText(String.valueOf(herb.getAmount()));
Clay clay = new Clay();
clay.setAmount((int)jSONArray.get(2));
clayAmount.setText(String.valueOf(clay.getAmount()));
Mineral mineral = new Mineral();
mineral.setAmount((int)jSONArray.get(3));
mineralAmount.setText(String.valueOf(mineral.getAmount()));
Potion potion = new Potion();
potion.setAmount((int)jSONArray.get(4));
potionAmount.setText(String.valueOf(potion.getAmount()));
Incense incense = new Incense();
incense.setAmount((int)jSONArray.get(5));
incenseAmount.setText(String.valueOf(incense.getAmount()));
Gem gem = new Gem();
gem.setAmount((int)jSONArray.get(6));
gemsAmount.setText(String.valueOf(gem.getAmount()));
LifeElixir lifeElixir = new LifeElixir();
lifeElixir.setAmount((int)jSONArray.get(7));
lifeelixirAmount.setText(String.valueOf(lifeElixir.getAmount()));
ManaCrystal manaCrystal = new ManaCrystal();
manaCrystal.setAmount((int)jSONArray.get(8));
manacrystalAmount.setText(String.valueOf(manaCrystal.getAmount()));
PhilosopherStone philosopherStone = new PhilosopherStone();
philosopherStone.setAmount((int)jSONArray.get(9));
connectionControler.closeConnection();
// Connection close
// JSONObject response = new JSONObject();
// response.put("inventory", new JSONArray(new Object[] {1,2,3,4,5,1,2,3,4,5}) );
// response.put("status", "ok");
// JOptionPane.showMessageDialog(rootPane, response.toString());
if ("ok".equals(response.getString("status")))
{
JSONArray jSONArray = response.getJSONArray("inventory");
Honey honey = new Honey();
honey.setAmount((int)jSONArray.get(0));
honeyAmount.setText(String.valueOf(honey.getAmount()));
Herb herb = new Herb();
herb.setAmount((int)jSONArray.get(1));
herbsAmount.setText(String.valueOf(herb.getAmount()));
Clay clay = new Clay();
clay.setAmount((int)jSONArray.get(2));
clayAmount.setText(String.valueOf(clay.getAmount()));
Mineral mineral = new Mineral();
mineral.setAmount((int)jSONArray.get(3));
mineralAmount.setText(String.valueOf(mineral.getAmount()));
Potion potion = new Potion();
potion.setAmount((int)jSONArray.get(4));
potionAmount.setText(String.valueOf(potion.getAmount()));
Incense incense = new Incense();
incense.setAmount((int)jSONArray.get(5));
incenseAmount.setText(String.valueOf(incense.getAmount()));
Gem gem = new Gem();
gem.setAmount((int)jSONArray.get(6));
gemsAmount.setText(String.valueOf(gem.getAmount()));
LifeElixir lifeElixir = new LifeElixir();
lifeElixir.setAmount((int)jSONArray.get(7));
lifeelixirAmount.setText(String.valueOf(lifeElixir.getAmount()));
ManaCrystal manaCrystal = new ManaCrystal();
manaCrystal.setAmount((int)jSONArray.get(8));
manacrystalAmount.setText(String.valueOf(manaCrystal.getAmount()));
PhilosopherStone philosopherStone = new PhilosopherStone();
philosopherStone.setAmount((int)jSONArray.get(9));
}
firstParamId = "";
secondParamId = "";
resultId = "";
......@@ -648,12 +660,27 @@ public class OfferWindow extends javax.swing.JFrame {
default : break;
}
jSONObject.put("method", "offer");
jSONObject.put("token", "contohtoken");
jSONObject.put("token", Avatar.token);
jSONObject.put("n1",Integer.valueOf(amountFirstParam.getValue().toString()));
jSONObject.put("n2",Integer.valueOf(amountSecondParam.getValue().toString()));
JOptionPane.showMessageDialog(rootPane, jSONObject.toString());
setVisible(false);
new MainWindow().setVisible(true);
JOptionPane.showMessageDialog(rootPane, jSONObject);
// Connection start
ConnectionControler connectionControler = new ConnectionControler(ConnectionControler.host, ConnectionControler.port);
connectionControler.sendMessage(jSONObject);
JOptionPane.showMessageDialog(rootPane, "Sent Message");
JSONObject response = connectionControler.receiveMessage();
JOptionPane.showMessageDialog(rootPane, response.toString());
connectionControler.closeConnection();
// Connection close
if ("ok".equals(response.getString("status")))
{
setVisible(false);
new MainWindow().setVisible(true);
}
else
{
JOptionPane.showMessageDialog(rootPane, "Error");
}
} catch (JSONException ex) {
Logger.getLogger(OfferWindow.class.getName()).log(Level.SEVERE, null, ex);
}
......
......@@ -27,6 +27,7 @@ import javax.swing.table.TableModel;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import thealchemist.controller.ConnectionControler;
import thealchemist.model.Avatar;
import thealchemist.model.Clay;
import thealchemist.model.Gem;
......@@ -69,10 +70,19 @@ public class TradeItemWindow extends javax.swing.JFrame {
jSONObject.put("method", "sendfind");
jSONObject.put("token", Avatar.token);
JOptionPane.showMessageDialog(rootPane, jSONObject.toString());
JSONObject response = new JSONObject();
response.put("status", "ok");
response.put("offers", new JSONArray(new Object[][]{{2,10,3,8,false,"token1"},{2,1,3,1,true,"token1"}} ));
if (response.get("status")=="ok")
// Connection start
ConnectionControler connectionControler = new ConnectionControler(ConnectionControler.host, ConnectionControler.port);
connectionControler.sendMessage(jSONObject);
JOptionPane.showMessageDialog(rootPane, "Sent Message");
JSONObject response = connectionControler.receiveMessage();
JOptionPane.showMessageDialog(rootPane, response.toString());
connectionControler.closeConnection();
// Connection close
// JSONObject response = new JSONObject();
// response.put("status", "ok");
// response.put("offers", new JSONArray(new Object[][]{{2,10,3,8,false,"token1"},{2,1,3,1,true,"token1"}} ));
if ("ok".equals(response.getString("status")))
{
Object rowData[][] = new Object[((JSONArray)response.get("offers")).length()][];
for (int i=0;i<((JSONArray)response.get("offers")).length();i++)
......@@ -109,20 +119,25 @@ public class TradeItemWindow extends javax.swing.JFrame {
{
if (item.getBoolean(j))
{
rowData[i][j] = "Cancel Offer";
rowData[i][j] = "Choose it";
}
else
else
{
rowData[i][j] = "Fetch Offer";
rowData[i][j] = "Cannot Choose";
}
}
else if (j==5)
{
// Action action = new
// rowData[i][j] = new JButton();
}
}
}
Object columnNames[] = {"Offered Item","Number Offered","Demanded Item","Number Demanded","Act"};
tableModel = new DefaultTableModel(rowData, columnNames);
initComponents();
jTable1.getColumn("Act").setCellRenderer(new ButtonRenderer());
jTable1.getColumn("Act").setCellEditor(new ButtonEditor(new JCheckBox()));
// jTable1.getColumn("Act").setCellEditor(new ButtonEditor(new JCheckBox()));
}
else
{
......@@ -145,15 +160,7 @@ public class TradeItemWindow extends javax.swing.JFrame {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable(tableModel){
// Returning the Class of each column will allow different
// renderers to be used based on Class
public Class getColumnClass(int column)
{
return getValueAt(0, column).getClass();
}
};
jTable1.setRowHeight(80);
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
......
......@@ -7,6 +7,7 @@
package thealchemist.view;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
......@@ -15,6 +16,7 @@ import javax.print.event.PrintJobEvent;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
......@@ -50,6 +52,11 @@ public class TradeboxWindow extends javax.swing.JFrame {
* Creates new form TradeboxWindow
*/
private TableModel tableModel;
public static void showMessageBox(String text)
{
JOptionPane.showInputDialog(text);
}
public TradeboxWindow() {
try {
JSONObject jSONObject = new JSONObject();
......@@ -72,7 +79,7 @@ public class TradeboxWindow extends javax.swing.JFrame {
Object rowData[][] = new Object[((JSONArray)response.get("offers")).length()][];
for (int i=0;i<((JSONArray)response.get("offers")).length();i++)
{
rowData[i] = new Object[5];
rowData[i] = new Object[6];
}
for (int i=0;i<((JSONArray)response.get("offers")).length();i++)
{
......@@ -111,13 +118,26 @@ public class TradeboxWindow extends javax.swing.JFrame {
rowData[i][j] = "Fetch Offer";
}
}
else if (j==5)
{
rowData[i][j] = item.getString(j);
}
}
}
Object columnNames[] = {"Offered Item","Number Offered","Demanded Item","Number Demanded","Act"};
Object columnNames[] = {"Offered Item","Number Offered","Demanded Item","Number Demanded","Act","Token"};
// GridLayout gridLayout = new GridLayout(((JSONArray)response.get("offers")).length(), 6);
tableModel = new DefaultTableModel(rowData, columnNames);
initComponents();
jTable1.getColumn("Act").setCellRenderer(new ButtonRenderer());
// for (int i=0;i<((JSONArray)response.get("offers")).length();i++)
// {
// jTable1 = new ButtonEditor(new JCheckBox());
// }
jPanel1.revalidate();
jPanel1.repaint();
// jTable1.getColumnModel().;
jTable1.getColumn("Act").setCellEditor(new ButtonEditor(new JCheckBox()));
}
else
{
......@@ -210,9 +230,8 @@ public class TradeboxWindow extends javax.swing.JFrame {
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
// TODO add your handling code here:
MainWindow mainWindow = new MainWindow();
setVisible(false);
mainWindow.setVisible(true);
new MainWindow().setVisible(true);
}//GEN-LAST:event_jButton1MouseClicked
/**
......@@ -290,11 +309,17 @@ class ButtonEditor extends DefaultCellEditor {
private String label;
private boolean isPushed;
private int row;
private int column;
private String offer_token;
public ButtonEditor(JCheckBox checkBox) {
super(checkBox);
button = new JButton();
button.setOpaque(true);
// this.offer_token = offer_token;
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -315,6 +340,9 @@ class ButtonEditor extends DefaultCellEditor {
}
label = (value == null) ? "" : value.toString();
button.setText(label);
this.row = row;
this.column = column;
this.offer_token = table.getValueAt(this.row, this.column+1).toString();
isPushed = true;
return button;
}
......@@ -322,10 +350,25 @@ class ButtonEditor extends DefaultCellEditor {
@Override
public Object getCellEditorValue() {
if (isPushed) {
//
//
JOptionPane.showMessageDialog(button, label + ": Ouch!");
// System.out.println(label + ": Ouch!");
try {
JOptionPane.showMessageDialog(button, label+" "+row+" "+column);
JSONObject jSONObject = new JSONObject();
jSONObject.put("method", "sendaccept");
jSONObject.put("token", Avatar.token);
jSONObject.put("offer_token", this.offer_token);
JOptionPane.showMessageDialog(button, jSONObject.toString());
// Connection start
ConnectionControler connectionControler = new ConnectionControler(ConnectionControler.host, ConnectionControler.port);
connectionControler.sendMessage(jSONObject);
JOptionPane.showMessageDialog(button, "Sent Message");
JSONObject response = connectionControler.receiveMessage();
JOptionPane.showMessageDialog(button, response.toString());
connectionControler.closeConnection();
// Connection close
// System.out.println(label + ": Ouch!");
} catch (JSONException ex) {
Logger.getLogger(ButtonEditor.class.getName()).log(Level.SEVERE, null, ex);
}
}
isPushed = false;
return new String(label);
......
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