Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void updateDisplay() {
- new Thread(
- () -> {
- if (catalogue == null)
- throw new Error("Internal error: catalogue not set");
- if (displayArea == null)
- throw new Error(
- "Internal error: display area not set");
- // Then do the display
- value = 0;
- Document doc = displayArea.getDocument();
- // For each item in the stock, add it to the description
- // list and the total value
- List<String> list = new ArrayList<String>();
- try {
- doc.remove(0, doc.getLength());
- for (String name : catalogue.getEntryNames()) {
- list.add(name);
- }
- list.parallelStream().forEach(n -> {
- try {
- IEntry entry = catalogue.getEntry(n);
- Product product = entry.getProduct();
- int quantity = entry.getQuantity();
- String text = product.getName() + "@"
- + product.getPrice() + ": " + quantity
- + "\n";
- doc.insertString(doc.getLength(), text, null);
- value += quantity * product.getPrice();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- });
- doc.insertString(doc.getLength(), "Total value: "
- + value, null);
- } catch (RemoteException exn) {
- throw new Error("Remote failure: " + exn);
- } catch (BadLocationException e) {
- throw new Error(
- "Internal error: bad text location in GUI");
- }
- }).start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement