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