1 import java.awt.*;
2 import java.awt.event.*;
3 import javax.swing.*;
4 import javax.swing.event.*;
5
6 /**
7
8 */
9 public class InvoiceTester
10 {
11 public static void main(String[] args)
12 {
13 Invoice invoice = new Invoice();
14 InvoiceFormatter formatter = new SimpleFormatter();
15
16 //
17 JTextArea textArea = new JTextArea(20, 40);
18
19 //
20 invoice.addChangeListener(event ->
21 textArea.setText(invoice.format(formatter)));
22
23 //
24 JComboBox<LineItem> combo = new JComboBox<>();
25 Product hammer = new Product("Hammer", 19.95);
26 Product nails = new Product("Assorted nails", 9.95);
27 combo.addItem(hammer);
28 Bundle bundle = new Bundle();
29 bundle.add(hammer);
30 bundle.add(nails);
31 combo.addItem(new DiscountedItem(bundle, 10));
32
33 //
34 //
35 JButton addButton = new JButton("Add");
36 addButton.addActionListener(event ->
37 {
38 LineItem item = combo.getItemAt(combo.getSelectedIndex());
39 invoice.addItem(item);
40 });
41
42 //
43 JPanel panel = new JPanel();
44 panel.add(combo);
45 panel.add(addButton);
46
47 //
48 JFrame frame = new JFrame();
49 frame.add(new JScrollPane(textArea),
50 BorderLayout.CENTER);
51 frame.add(panel, BorderLayout.SOUTH);
52 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53 frame.pack();
54 frame.setVisible(true);
55 }
56 }