This commit is contained in:
Daniil Gentili 2017-11-04 20:20:11 +03:00
parent a7de077ff7
commit 61ad7d089a
7 changed files with 21 additions and 32 deletions

View File

@ -18,7 +18,7 @@ package Main;
/**
*
* @author Studente
* @author Daniil Gentili
*/
public class Cart extends Container {
public Cart(String input) {

View File

@ -19,8 +19,6 @@ package Main;
import Payloads.RequestPayload;
import Payloads.ResponsePayload;
import Payloads.ServerException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
@ -30,9 +28,9 @@ import java.net.Socket;
/**
*
* @author root
* @author Daniil Gentili
*/
public class Client implements ActionListener {
public class Client {
private BufferedWriter out;
private BufferedReader in;
@ -70,7 +68,6 @@ public class Client implements ActionListener {
}
public void commit() throws IOException, ServerException {
RequestPayload request = new RequestPayload("POST", "/", cart.getPayload());
request.shouldKeepAlive(true);
request.write(out);
@ -80,21 +77,7 @@ public class Client implements ActionListener {
if (response.getResponseCode() != 200) {
throw new ServerException(response);
}
warehouse = new Warehouse(response.getPayload());
cart = new Cart();
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(e.paramString());
/* if (e.getText().equals("Buy")) {
try {
this.addToCart(Integer.parseInt(e.getActionCommand()));
} catch (ClientException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
}
*/
this.warehouse.rebuild(response.getPayload());
this.cart.rebuild();
}
}

View File

@ -18,7 +18,7 @@ package Main;
/**
*
* @author root
* @author Daniil Gentili
*/
public class ClientException extends Exception {

View File

@ -20,7 +20,7 @@ import java.util.Hashtable;
/**
*
* @author root
* @author Daniil Gentili
*/
public abstract class Container
{
@ -32,6 +32,17 @@ public abstract class Container
Constructors
*/
public Container(String response) {
rebuild(response);
}
public Container() {
rebuild();
}
public void rebuild() {
this.products.clear();
}
public void rebuild(String response) {
this.products.clear();
String[] split;
for (String line: response.split("\n")) {
split = line.split(";");
@ -48,11 +59,6 @@ public abstract class Container
);
}
}
public Container() {
}
/**
* Get the string payload of the container
* @return The string payload

View File

@ -18,7 +18,7 @@ package Main;
/**
*
* @author Studente
* @author Daniil Gentili
*/
public class Product {
private Double price;

View File

@ -19,7 +19,7 @@ package Main;
/**
*
* @author root
* @author Daniil Gentili
*/
public class ProductCollection {
private final Product product;

View File

@ -18,7 +18,7 @@ package Main;
/**
*
* @author root
* @author Daniil Gentili
*/
public class Warehouse extends Container {
public Warehouse(String input) {