Commit 0925480f authored by melvinfonda's avatar melvinfonda
Browse files
parents 6a837242 94204056
......@@ -1121,15 +1121,29 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="884" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Component id="tradeboxScrollPane" min="-2" pref="847" max="-2" attributes="0"/>
<EmptySpace pref="18" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="540" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="20" max="32767" attributes="0"/>
<Component id="tradeboxScrollPane" min="-2" pref="500" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="20" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="tradeboxScrollPane">
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="offerPanel">
<Constraints>
......
......@@ -43,10 +43,12 @@ public class MainPage extends javax.swing.JFrame {
private Date currentTime;
private Date time;
private Timer timer;
private TableModel tradeboxModel;
public MainPage() {
mapModel=new MapTableModel();
tradeboxModel=new MapTableModel();
initComponents();
//mapTable
......@@ -138,6 +140,7 @@ public class MainPage extends javax.swing.JFrame {
StoneCount = new javax.swing.JLabel();
mixitemPanel = new javax.swing.JPanel();
tradeboxPanel = new javax.swing.JPanel();
tradeboxScrollPane = new javax.swing.JScrollPane();
offerPanel = new javax.swing.JPanel();
finditemPanel = new javax.swing.JPanel();
tradeitemPanel = new javax.swing.JPanel();
......@@ -840,11 +843,17 @@ public class MainPage extends javax.swing.JFrame {
tradeboxPanel.setLayout(tradeboxPanelLayout);
tradeboxPanelLayout.setHorizontalGroup(
tradeboxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 884, Short.MAX_VALUE)
.addGroup(tradeboxPanelLayout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(tradeboxScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 847, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(18, Short.MAX_VALUE))
);
tradeboxPanelLayout.setVerticalGroup(
tradeboxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 540, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tradeboxPanelLayout.createSequentialGroup()
.addContainerGap(20, Short.MAX_VALUE)
.addComponent(tradeboxScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(20, 20, 20))
);
MainPanel.add(tradeboxPanel, "TradeBoxCard");
......@@ -951,6 +960,8 @@ public class MainPage extends javax.swing.JFrame {
}//GEN-LAST:event_MixItemMenuButtonActionPerformed
private void TradeBoxMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TradeBoxMenuButtonActionPerformed
generateTradebox();
CardLayout cl = (CardLayout) MainPanel.getLayout();
cl.show(MainPanel, "TradeBoxCard");
}//GEN-LAST:event_TradeBoxMenuButtonActionPerformed
......@@ -1157,9 +1168,8 @@ public class MainPage extends javax.swing.JFrame {
//Generate Map
private void generateMap() {
JSONObject response;
try {
response = client.map();
JSONObject response = client.map();
if(response.getString("status").equals("ok")) {
String name = response.getString("name");
......@@ -1197,6 +1207,20 @@ public class MainPage extends javax.swing.JFrame {
}
}
private void generateTradebox(){
try {
JSONObject response = client.tradebox();
} catch (Exception ex) {
showMessage("Server tradebox does not respond. Please try again later..");
System.out.println("Tradebox Exception");
Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @param args the command line arguments
*/
......@@ -1305,6 +1329,7 @@ public class MainPage extends javax.swing.JFrame {
private javax.swing.JPanel settingPanel;
private javax.swing.JLabel timeLabel;
private javax.swing.JPanel tradeboxPanel;
private javax.swing.JScrollPane tradeboxScrollPane;
private javax.swing.JPanel tradeitemPanel;
private javax.swing.JLabel usernameLoginLabel;
private javax.swing.JTextField usernameLoginTextField;
......
......@@ -147,6 +147,31 @@ public class TCPClient {
return obj;
}
private Object tradeboxJSON(String token) {
JSONObject obj = new JSONObject();
try {
obj.put("method", "tradebox");
obj.put("token", token);
} catch(Exception e) {
e.printStackTrace();
}
return obj;
}
private Object sendAcceptJSON(String offerToken) {
JSONObject obj = new JSONObject();
try {
obj.put("method", "sendaccept");
obj.put("token", token);
obj.put("offer_token", offerToken);
} catch(Exception e) {
e.printStackTrace();
}
return obj;
}
public JSONObject cancelofferJSON(String token, String offer_token) {
JSONObject obj = new JSONObject();
......@@ -346,6 +371,52 @@ public class TCPClient {
return responseJSON;
}
public JSONObject tradebox() throws Exception
{
System.out.println("Tradebox");
String toSend = tradeboxJSON(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 tradebox exception");
}
//ambil balasan server
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String response = inFromServer.readLine();
JSONObject responseJSON = new JSONObject(response);
return responseJSON;
}
public JSONObject sendAccept(String offerToken) throws Exception
{
System.out.println("Send Accept");
String toSend = sendAcceptJSON(offerToken).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 send accept exception");
}
//ambil balasan server
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String response = inFromServer.readLine();
JSONObject responseJSON = new JSONObject(response);
return responseJSON;
}
public JSONObject canceloffer(String token, String offer_token) throws Exception
{
System.out.println("Cancel Offer");
......@@ -496,4 +567,6 @@ public class TCPClient {
System.out.println(response.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