zadanie 1

This commit is contained in:
2023-01-14 16:45:35 +01:00
parent 6659f96257
commit b6a0ca935a
2 changed files with 24 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ class BookSellerGui extends JFrame
{
private BookSellerAgent myAgent;
private JTextField titleField, priceField;
private JTextField titleField, priceField, shippingPriceField;
BookSellerGui(BookSellerAgent a)
{
@@ -19,28 +19,42 @@ class BookSellerGui extends JFrame
myAgent = a;
JPanel p = new JPanel();
p.setLayout(new GridLayout(2, 2));
p.setLayout(new GridLayout(3, 2));
p.add(new JLabel("Title:"));
titleField = new JTextField(15);
p.add(titleField);
p.add(new JLabel("Price:"));
priceField = new JTextField(15);
p.add(priceField);
p.add(new JLabel("Shipping cost:"));
shippingPriceField = new JTextField(15);
p.add(shippingPriceField);
getContentPane().add(p, BorderLayout.CENTER);
JButton addButton = new JButton("Add");
addButton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent ev) {
public void actionPerformed(ActionEvent ev)
{
try
{
String title = titleField.getText().trim();
String price = priceField.getText().trim();
myAgent.updateCatalogue(title, Integer.parseInt(price));
String shippingPrice = shippingPriceField.getText().trim();
myAgent.updateCatalogue(title, Integer.parseInt(price), Integer.parseInt(shippingPrice));
titleField.setText("");
priceField.setText("");
shippingPriceField.setText("");
}
catch (Exception e) {
catch (Exception e)
{
JOptionPane.showMessageDialog(BookSellerGui.this, "Invalid values. " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}