Commit 475aa3fb authored by Jonathan Sudibya's avatar Jonathan Sudibya
Browse files

checkpoint client #1

parent addd6759
...@@ -82,7 +82,7 @@ public class Field extends javax.swing.JFrame { ...@@ -82,7 +82,7 @@ public class Field extends javax.swing.JFrame {
findp = new findpanel(); findp = new findpanel();
offerp = new OfferPanel(); offerp = new OfferPanel();
tradebx = new TradePanel(user); tradebx = new TradePanel(user);
Itemt = new ItemTrade(); Itemt = new ItemTrade(user);
NamaField.setText(mapjson.get("name").toString()); NamaField.setText(mapjson.get("name").toString());
CharPosition.setText("Pos : " +userJSON.get("x")+" , "+userJSON.get("y")); CharPosition.setText("Pos : " +userJSON.get("x")+" , "+userJSON.get("y"));
connector = new TCPClient(); connector = new TCPClient();
......
...@@ -54,9 +54,6 @@ ...@@ -54,9 +54,6 @@
<SubComponents> <SubComponents>
<Component class="javax.swing.JTable" name="jTable1"> <Component class="javax.swing.JTable" name="jTable1">
<Properties> <Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="0" rowCount="2"/>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor"> <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0"/> <TableColumnModel selectionModel="0"/>
</Property> </Property>
...@@ -65,7 +62,7 @@ ...@@ -65,7 +62,7 @@
</Property> </Property>
</Properties> </Properties>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new JTable(){&#xa; public Class getColumnClass(int column)&#xa; {&#xa; return getValueAt(0, column).getClass();&#xa; }&#xa;}"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new JTable(model){&#xa; public Class getColumnClass(int column){&#xa; if (column == 0 || column == 2){&#xa; return ImageIcon.class;&#xa; }else{&#xa; return Object.class;&#xa; }&#xa; }&#xa;}"/>
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setRowHeight(45);&#xa;jTable1.getColumn(&quot;Act&quot;).setCellRenderer(new ButtonRenderer());&#xa; jTable1.getColumn(&quot;Act&quot;).setCellEditor(&#xa; new ButtonEditor(new JCheckBox()));&#xa; setVisible(true);"/> <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setRowHeight(45);&#xa;jTable1.getColumn(&quot;Act&quot;).setCellRenderer(new ButtonRenderer());&#xa; jTable1.getColumn(&quot;Act&quot;).setCellEditor(&#xa; new ButtonEditor(new JCheckBox()));&#xa; setVisible(true);"/>
</AuxValues> </AuxValues>
</Component> </Component>
......
...@@ -8,6 +8,8 @@ package client; ...@@ -8,6 +8,8 @@ package client;
import java.awt.Component; import java.awt.Component;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultCellEditor; import javax.swing.DefaultCellEditor;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
...@@ -20,6 +22,9 @@ import javax.swing.JTable; ...@@ -20,6 +22,9 @@ import javax.swing.JTable;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
/** /**
* *
...@@ -31,24 +36,88 @@ public class ItemTrade extends javax.swing.JPanel { ...@@ -31,24 +36,88 @@ public class ItemTrade extends javax.swing.JPanel {
* Creates new form TradePanel * Creates new form TradePanel
*/ */
private DefaultTableModel model; private DefaultTableModel model;
private JLabel Gem; private JLabel Gem, Gem2;
private Item[] items; private Item[] items;
private JSONObject JSONtable;
private Object[][] data;
public ItemTrade() { private void getmatrixofitem(){
for (int i = 0 ;i<10; i++){
items[i] = new Item();
items[i].setID(i);
}
for (int i = 0 ;i<10; i++){
items[i].setIcon();
}
}
public ItemTrade(String user) {
this.setSize(655,519); this.setSize(655,519);
JLabel Gem = new JLabel(); items = new Item[10];
Gem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/image/gem.png"))); getmatrixofitem();
String[] columnNames = {"Offered Item", "Number Offered", "Demmanded Item", "Number Demmanded", "Act"}; Gem = new JLabel();
Gem2 = new JLabel();
TCPClient connector = new TCPClient();
Object[][] data = String[] columnNames = {"Offered Item", "Number Offered", "Demmanded Item", "Number Demmanded", "Act", "token"};
{
{Gem.getIcon(),3, Gem.getIcon(), 4, "test"},
};
model = new DefaultTableModel(data, columnNames); String Message = "{ \"method\" : \"tradebox\",\"token\" : \""+user+"\"}";
JSONObject campur = new JSONObject();
try {
campur = connector.login(Message);
} catch (Exception ex) {
Logger.getLogger(Field.class.getName()).log(Level.SEVERE, null, ex);
}
JSONArray tawaran = new JSONArray();
tawaran = (JSONArray) campur.get("offers");
data = new Object [tawaran.size()][];
for(int i=0;i<tawaran.size();i++){
data[i] = new Object[6];
}
for(int i=0;i<tawaran.size();i++){
JSONParser parser = new JSONParser();
JSONArray item = (JSONArray) tawaran.get(i);
System.out.println(item.get(0).toString());
for (int j=0;j<6;j++){
if (j==0){
Integer K = (int) (long) item.get(0);
Gem.setIcon(items[K].getIcon().getIcon());
data[i][j] = Gem.getIcon();
}
else if(j==2){
Integer K = (int) (long) item.get(2);
int n = (int) K;
System.out.println(n);
Gem.setIcon(items[n].getIcon().getIcon());
data[i][j] = Gem.getIcon();
}
else if(j==1){
data[i][j] = item.get(1);
}
else if(j==3){
data[i][j] = item.get(3);
}
else if(j==4){
String tersedia = item.get(4).toString();
if ("true".equals(tersedia)){
data[i][j] = "Cancel";
} else {
data[i][j] = "Fetch";
}
}
else if (j==5){
data[i][j] = item.get(5);
}
}
}
model = new DefaultTableModel(data, columnNames);
initComponents(); initComponents();
this.setVisible(false);
} }
/** /**
...@@ -61,25 +130,19 @@ public class ItemTrade extends javax.swing.JPanel { ...@@ -61,25 +130,19 @@ public class ItemTrade extends javax.swing.JPanel {
private void initComponents() { private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new JTable(){ jTable1 = new JTable(model){
public Class getColumnClass(int column) public Class getColumnClass(int column){
{ if (column == 0 || column == 2){
return getValueAt(0, column).getClass(); return ImageIcon.class;
}else{
return Object.class;
}
} }
}; };
Back = new javax.swing.JButton(); Back = new javax.swing.JButton();
setPreferredSize(new java.awt.Dimension(655, 513)); setPreferredSize(new java.awt.Dimension(655, 513));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{},
{}
},
new String [] {
}
));
jTable1.setRowHeight(45); jTable1.setRowHeight(45);
jTable1.getColumn("Act").setCellRenderer(new ButtonRenderer()); jTable1.getColumn("Act").setCellRenderer(new ButtonRenderer());
jTable1.getColumn("Act").setCellEditor( jTable1.getColumn("Act").setCellEditor(
...@@ -121,15 +184,8 @@ public class ItemTrade extends javax.swing.JPanel { ...@@ -121,15 +184,8 @@ public class ItemTrade extends javax.swing.JPanel {
map.setVisible(true); map.setVisible(true);
this.setVisible(false); this.setVisible(false);
}//GEN-LAST:event_BackActionPerformed }//GEN-LAST:event_BackActionPerformed
public static void main(String args[]) {
JFrame frame = new JFrame();
ItemTrade in = new ItemTrade();
frame.add(in);
frame.setVisible(true);
}
class ButtonRenderer extends JButton implements TableCellRenderer { public class ButtonRenderer extends JButton implements TableCellRenderer {
public ButtonRenderer() { public ButtonRenderer() {
setOpaque(true); setOpaque(true);
......
...@@ -53,13 +53,8 @@ ...@@ -53,13 +53,8 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents> <SubComponents>
<Component class="javax.swing.JTable" name="jTable1"> <Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="model" type="code"/>
</Property>
</Properties>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new JTable(){&#xa; public Class getColumnClass(int column)&#xa; {&#xa; return getValueAt(0, column).getClass();&#xa; }&#xa;}"/> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JTable(model){&#xa;&#xa; public Class getColumnClass(int column){&#xa; if (column == 0 || column == 2){&#xa; return ImageIcon.class;&#xa; }else{&#xa; return Object.class;&#xa; }&#xa; }&#xa;}"/>
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setRowHeight(45);&#xa;jTable1.getColumn(&quot;Act&quot;).setCellRenderer(new ButtonRenderer());&#xa; jTable1.getColumn(&quot;Act&quot;).setCellEditor(&#xa; new ButtonEditor(new JCheckBox()));&#xa; setVisible(true);"/> <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setRowHeight(45);&#xa;jTable1.getColumn(&quot;Act&quot;).setCellRenderer(new ButtonRenderer());&#xa; jTable1.getColumn(&quot;Act&quot;).setCellEditor(&#xa; new ButtonEditor(new JCheckBox()));&#xa; setVisible(true);"/>
</AuxValues> </AuxValues>
</Component> </Component>
......
...@@ -24,7 +24,10 @@ import javax.swing.UIManager; ...@@ -24,7 +24,10 @@ import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.JSONException;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/** /**
* *
...@@ -39,6 +42,7 @@ public class TradePanel extends javax.swing.JPanel { ...@@ -39,6 +42,7 @@ public class TradePanel extends javax.swing.JPanel {
private JLabel Gem, Gem2; private JLabel Gem, Gem2;
private Item[] items; private Item[] items;
private JSONObject JSONtable; private JSONObject JSONtable;
private Object[][] data;
private void getmatrixofitem(){ private void getmatrixofitem(){
for (int i = 0 ;i<10; i++){ for (int i = 0 ;i<10; i++){
...@@ -57,17 +61,19 @@ public class TradePanel extends javax.swing.JPanel { ...@@ -57,17 +61,19 @@ public class TradePanel extends javax.swing.JPanel {
offers = (JSONArray) JSONtable.get("offers"); offers = (JSONArray) JSONtable.get("offers");
model.removeRow(0); model.removeRow(0);
for(int i=0; i<offers.size(); i++) { for(int i=0; i<offers.size(); i++) {
offer = (JSONObject) offers.get(i);
int OI = (int) offer.get("offered_item"); offer = (JSONObject) offers.get(i);
int DI = (int) offer.get("demanded_item"); int OI = (int) offer.get("offered_item");
int N1 = (int) offer.get("n1"); int DI = (int) offer.get("demanded_item");
int N2 = (int) offer.get("n2"); int N1 = (int) offer.get("n1");
boolean Ava = (boolean) offer.get("Available"); int N2 = (int) offer.get("n2");
items[N1].setIcon(); boolean Ava = (boolean) offer.get("Available");
Gem.setIcon(items[N1].getIcon().getIcon()); items[N1].setIcon();
items[N2].setIcon(); Gem.setIcon(items[N1].getIcon().getIcon());
Gem2.setIcon(items[N2].getIcon().getIcon()); items[N2].setIcon();
model.addRow(new Object[]{Gem.getIcon(), OI, Gem2.getIcon(), DI, "true"}); Gem2.setIcon(items[N2].getIcon().getIcon());
model.addRow(new Object[]{Gem.getIcon(),OI,Gem2.getIcon(),DI,"true"});
} }
} }
...@@ -80,7 +86,7 @@ public class TradePanel extends javax.swing.JPanel { ...@@ -80,7 +86,7 @@ public class TradePanel extends javax.swing.JPanel {
Gem2 = new JLabel(); Gem2 = new JLabel();
TCPClient connector = new TCPClient(); TCPClient connector = new TCPClient();
String[] columnNames = {"Offered Item", "Number Offered", "Demmanded Item", "Number Demmanded", "Act"}; String[] columnNames = {"Offered Item", "Number Offered", "Demmanded Item", "Number Demmanded", "Act", "token"};
String Message = "{ \"method\" : \"tradebox\",\"token\" : \""+user+"\"}"; String Message = "{ \"method\" : \"tradebox\",\"token\" : \""+user+"\"}";
JSONObject campur = new JSONObject(); JSONObject campur = new JSONObject();
...@@ -90,36 +96,54 @@ public class TradePanel extends javax.swing.JPanel { ...@@ -90,36 +96,54 @@ public class TradePanel extends javax.swing.JPanel {
Logger.getLogger(Field.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Field.class.getName()).log(Level.SEVERE, null, ex);
} }
JSONArray tawaran = new JSONArray(); JSONArray tawaran = new JSONArray();
tawaran = (JSONArray) campur.get("offers") ; tawaran = (JSONArray) campur.get("offers");
Object[][] data = new Object [tawaran.size()][]; data = new Object [tawaran.size()][];
for(int i=0;i<tawaran.size();i++){ for(int i=0;i<tawaran.size();i++){
data[i] = new Object[6]; data[i] = new Object[6];
} }
for(int i=0;i<tawaran.size();i++){ for(int i=0;i<tawaran.size();i++){
JSONObject item = (JSONObject) tawaran.get(i);
for (int j = 0; j < 6; j++) { JSONParser parser = new JSONParser();
if (j == 0) { JSONArray item = (JSONArray) tawaran.get(i);
data[i][j] = Gem.getIcon(); System.out.println(item.get(0).toString());
} else if (j == 2) { for (int j=0;j<6;j++){
if (j==0){
} else if (j == 1 || j == 3) { Integer K = (int) (long) item.get(0);
Gem.setIcon(items[K].getIcon().getIcon());
} else if (j == 4) { data[i][j] = Gem.getIcon();
String tersedia = item.get("Available").toString(); }
if ("true".equals(tersedia)) { else if(j==2){
// data[i][j] = ; Integer K = (int) (long) item.get(2);
} else { int n = (int) K;
data[i][j] = ""; System.out.println(n);
Gem.setIcon(items[n].getIcon().getIcon());
data[i][j] = Gem.getIcon();
}
else if(j==1){
data[i][j] = item.get(1);
}
else if(j==3){
data[i][j] = item.get(3);
}
else if(j==4){
String tersedia = item.get(4).toString();
if ("true".equals(tersedia)){
data[i][j] = "Cancel";
} else {
data[i][j] = "Fetch";
}
}
else if (j==5){
data[i][j] = item.get(5);
} }
} else if (j == 5) {
} }
}
} }
model = new DefaultTableModel(data, columnNames); model = new DefaultTableModel(data, columnNames);
initComponents(); initComponents();
this.setVisible(false);
} }
/** /**
...@@ -132,17 +156,20 @@ public class TradePanel extends javax.swing.JPanel { ...@@ -132,17 +156,20 @@ public class TradePanel extends javax.swing.JPanel {
private void initComponents() { private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new JTable(){ jTable1 = new javax.swing.JTable(model){
public Class getColumnClass(int column)
{ public Class getColumnClass(int column){
return getValueAt(0, column).getClass(); if (column == 0 || column == 2){
return ImageIcon.class;
}else{
return Object.class;
}
} }
}; };
Back = new javax.swing.JButton(); Back = new javax.swing.JButton();
setPreferredSize(new java.awt.Dimension(655, 513)); setPreferredSize(new java.awt.Dimension(655, 513));
jTable1.setModel(model);
jTable1.setRowHeight(45); jTable1.setRowHeight(45);
jTable1.getColumn("Act").setCellRenderer(new ButtonRenderer()); jTable1.getColumn("Act").setCellRenderer(new ButtonRenderer());
jTable1.getColumn("Act").setCellEditor( jTable1.getColumn("Act").setCellEditor(
...@@ -184,17 +211,8 @@ public class TradePanel extends javax.swing.JPanel { ...@@ -184,17 +211,8 @@ public class TradePanel extends javax.swing.JPanel {
map.setVisible(true); map.setVisible(true);
this.setVisible(false); this.setVisible(false);
}//GEN-LAST:event_BackActionPerformed }//GEN-LAST:event_BackActionPerformed
//public static void main(String args[]) {
// JFrame frame = new JFrame();
// TradePanel in = new TradePanel();
// frame.add(in);
// frame.setVisible(true);
//
// }
public
class ButtonRenderer extends JButton implements TableCellRenderer { public class ButtonRenderer extends JButton implements TableCellRenderer {
public ButtonRenderer() { public ButtonRenderer() {
setOpaque(true); setOpaque(true);
...@@ -250,8 +268,7 @@ class ButtonEditor extends DefaultCellEditor { ...@@ -250,8 +268,7 @@ class ButtonEditor extends DefaultCellEditor {
public Object getCellEditorValue() { public Object getCellEditorValue() {
if (isPushed) { if (isPushed) {
//
//
JOptionPane.showMessageDialog(button, label + ": Ouch!"); JOptionPane.showMessageDialog(button, label + ": Ouch!");
// System.out.println(label + ": Ouch!"); // System.out.println(label + ": Ouch!");
} }
......
...@@ -26,6 +26,7 @@ public class findpanel extends JPanel{ ...@@ -26,6 +26,7 @@ public class findpanel extends JPanel{
public findpanel(){ public findpanel(){
this.setSize(655,519); this.setSize(655,519);
initComponents(); initComponents();
Canvas = new JPanel();
} }
public void setJSON(JSONObject in){ public void setJSON(JSONObject in){
...@@ -67,6 +68,7 @@ public class findpanel extends JPanel{ ...@@ -67,6 +68,7 @@ public class findpanel extends JPanel{
LifeElixir.setText(items[7].ShowJumlah()); LifeElixir.setText(items[7].ShowJumlah());
Crystal.setText(items[8].ShowJumlah()); Crystal.setText(items[8].ShowJumlah());
PhilosopherStone.setText(items[9].ShowJumlah()); PhilosopherStone.setText(items[9].ShowJumlah());
Itemtrade = new ItemTrade((String) invenJSON.get("token"));
Canvas.add(Itemtrade); Canvas.add(Itemtrade);
} }
...@@ -93,7 +95,7 @@ public class findpanel extends JPanel{ ...@@ -93,7 +95,7 @@ public class findpanel extends JPanel{
item1 = new javax.swing.JLabel(); item1 = new javax.swing.JLabel();
cancel = new javax.swing.JButton(); cancel = new javax.swing.JButton();
find = new javax.swing.JButton(); find = new javax.swing.JButton();
Itemtrade = new ItemTrade();
Level1.setBackground(new java.awt.Color(153, 255, 51)); Level1.setBackground(new java.awt.Color(153, 255, 51));
...@@ -344,6 +346,7 @@ public class findpanel extends JPanel{ ...@@ -344,6 +346,7 @@ public class findpanel extends JPanel{
} }
public void setPanel(JPanel _panel){ public void setPanel(JPanel _panel){
Canvas = _panel; Canvas = _panel;
} }
// Variables declaration - do not modify // Variables declaration - do not modify
......
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