Commit acc8545b authored by Timothy Pratama's avatar Timothy Pratama
Browse files

(client) fix find item GUI.

parent ae2fa120
......@@ -164,7 +164,7 @@
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="220" y="430" width="-1" height="-1"/>
<AbsoluteConstraints x="270" y="420" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
......@@ -192,7 +192,7 @@
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="260" y="430" width="170" height="-1"/>
<AbsoluteConstraints x="310" y="420" width="170" height="-1"/>
</Constraint>
</Constraints>
</Component>
......@@ -205,7 +205,7 @@
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="290" y="470" width="-1" height="-1"/>
<AbsoluteConstraints x="340" y="460" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
......
......@@ -115,7 +115,7 @@ public class FindItemScreen extends javax.swing.JFrame {
item_label.setText("Item");
getContentPane().add(item_label);
item_label.setBounds(220, 430, 25, 16);
item_label.setBounds(270, 420, 25, 16);
jComboBox1.setMaximumRowCount(5);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--- Select an Item ---", "Honey", "Herbs", "Clay", "Mineral", "Potion", "Incense", "Gems", "Life Elixir", "Mana Crystal", "Philosopher Stone" }));
......@@ -125,7 +125,7 @@ public class FindItemScreen extends javax.swing.JFrame {
}
});
getContentPane().add(jComboBox1);
jComboBox1.setBounds(260, 430, 170, 25);
jComboBox1.setBounds(310, 420, 170, 25);
find_button.setText("Find");
find_button.addActionListener(new java.awt.event.ActionListener() {
......@@ -134,7 +134,7 @@ public class FindItemScreen extends javax.swing.JFrame {
}
});
getContentPane().add(find_button);
find_button.setBounds(290, 470, 57, 26);
find_button.setBounds(340, 460, 57, 26);
background_label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/sendfine_background.png"))); // NOI18N
getContentPane().add(background_label);
......
......@@ -123,24 +123,24 @@ public class Helper {
DataOutputStream output = new DataOutputStream(client.getOutputStream());
/* Python Server */
output.write(message.getBytes());
// output.write(message.getBytes());
/* Server Java */
// output.writeUTF(message);
output.writeUTF(message);
InputStream stream = client.getInputStream();
/* Pthyon Server */
byte[] data = new byte[4096];
int count = stream.read(data);
String response = new String(data);
// byte[] data = new byte[4096];
// int count = stream.read(data);
// String response = new String(data);
/* Server Java */
// DataInputStream input = new DataInputStream(stream);
// String response = input.readUTF();
DataInputStream input = new DataInputStream(stream);
String response = input.readUTF();
/* Python Server */
response = response.substring(0, count);
// response = response.substring(0, count);
/* Server Java */
......
......@@ -26,6 +26,10 @@ import org.json.simple.parser.ParseException;
*/
public class SearchResultScreen extends javax.swing.JFrame {
private JLabel [] labels;
private ImageIcon [] icons;
private JButton[] buttons;
/**
* Creates new form FindResultScreen
*/
......@@ -134,9 +138,9 @@ public class SearchResultScreen extends javax.swing.JFrame {
try
{
JSONArray offers = (JSONArray) parser.parse(Global.SuccessMessage);
JLabel [] labels = new JLabel[offers.size()*4];
ImageIcon [] icons = new ImageIcon[offers.size()*4];
JButton[] buttons = new JButton[offers.size()];
labels = new JLabel[offers.size()*4];
icons = new ImageIcon[offers.size()*4];
buttons = new JButton[offers.size()];
System.out.println("Offers: " + offers.toJSONString());
int j = 0;
int k = 0;
......@@ -188,9 +192,11 @@ public class SearchResultScreen extends javax.swing.JFrame {
buttons[k] = new JButton();
canvas_main_panel.add(buttons[k]);
buttons[k].setText("Buy");
int index1 = j;
int index2 = k;
buttons[k].addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SendAccept(evt, temp.get(5).toString());
SendAccept(evt, temp.get(5).toString(), index1, index2);
}
});
k++;
......@@ -215,11 +221,17 @@ public class SearchResultScreen extends javax.swing.JFrame {
dispose();
}//GEN-LAST:event_back_buttonActionPerformed
private void SendAccept(java.awt.event.ActionEvent evt, String other_token) {
private void SendAccept(java.awt.event.ActionEvent evt, String other_token, int index1, int index2) {
boolean success = Helper.sendAccept(other_token);
if(success)
{
JOptionPane.showMessageDialog(this, Global.SuccessMessage);
canvas_main_panel.remove(labels[index1-1]);
canvas_main_panel.remove(labels[index1-2]);
canvas_main_panel.remove(labels[index1-3]);
canvas_main_panel.remove(labels[index1-4]);
canvas_main_panel.remove(buttons[index2]);
repaint();
}
else
{
......
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