Пример #1
0
    public void actionPerformed(ActionEvent e) {
      if (fileChooser.showSaveDialog(panel5) == JFileChooser.APPROVE_OPTION) {
        try {
          FileOutputStream fileOutput =
              new FileOutputStream(fileChooser.getSelectedFile().getPath());
          String s = "Shop: " + shop.getName() + "\n";
          s = s + "VideoTechnik v nalichii\n";
          for (int i = 0; i < shop.getVideoTechnik().size(); i++) {
            VideoTechnik video = (VideoTechnik) shop.getVideoTechnik().get(i);
            s = s + "---";
            s = s + "Name " + video.getName() + "     Proizvoditel: " + video.getProizvod() + "\n";
            s =
                s
                    + "    Price: "
                    + video.getPrice()
                    + "     Quantity: "
                    + video.getQuantity()
                    + "\n";
          }
          s = s + "\nProdannaya VideoTechnik\n";
          for (int j = 0; j < prodanVideo.size(); j++) {
            s = s + prodanVideo.get(j) + "\n";
          }

          fileOutput.write(s.getBytes());
          fileOutput.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(panel5, "I don't know this EXCEPTION\n" + ex.getMessage());
        }
      } else return;
    }
Пример #2
0
    public void valueChanged(ListSelectionEvent a) {
      if (listBefore.getSelectedValue() != null) {
        VideoTechnik v = (VideoTechnik) listBefore.getSelectedValue();

        textName.setText(v.getName());
        textProizvod.setText(v.getProizvod());
        textPrice.setText(String.valueOf(v.getPrice()));
        textQuantity.setText(String.valueOf(v.getQuantity()));
      } else {
        textName.setText("");
        textProizvod.setText("");
        textPrice.setText("");
        textQuantity.setText("");
      }
    }
Пример #3
0
    // Konstructor VideoDialog(VideoTechnik vid)
    public VideoDialog(VideoTechnik vid) {
      this.setSize(400, 300);
      this.setTitle("Изменение VideoTechnik");
      this.setModal(true);

      p1.setPreferredSize(new Dimension(200, 200));
      p1.setBackground(Color.orange);
      this.getContentPane().add(p1);

      l.setForeground(Color.red);
      l.setText("Параметры VideoTechnik");
      l.setPreferredSize(new Dimension(300, 30));
      label_Name.setText("Название");
      label_Name.setPreferredSize(new Dimension(130, 30));
      label_Proizvod.setText("Производитель");
      label_Proizvod.setPreferredSize(new Dimension(130, 30));
      label_Price.setText("Цена");
      label_Price.setPreferredSize(new Dimension(130, 30));
      label_Quantity.setText("Количество");
      label_Quantity.setPreferredSize(new Dimension(130, 30));

      text_Name.setPreferredSize(new Dimension(200, 30));
      text_Proizvod.setPreferredSize(new Dimension(200, 30));
      text_Price.setPreferredSize(new Dimension(200, 30));
      text_Quantity.setPreferredSize(new Dimension(200, 30));

      butCancel.setPreferredSize(new Dimension(110, 30));
      butOk.setPreferredSize(new Dimension(60, 30));

      p1.add(l);
      p1.add(label_Name);
      p1.add(text_Name);
      p1.add(label_Proizvod);
      p1.add(text_Proizvod);
      p1.add(label_Price);
      p1.add(text_Price);
      p1.add(label_Quantity);
      p1.add(text_Quantity);
      p1.add(butOk);
      p1.add(butCancel);

      v = vid;
      text_Name.setText(String.valueOf(v.getName()));
      text_Proizvod.setText(String.valueOf(v.getProizvod()));
      text_Price.setText(String.valueOf(v.getPrice()));
      text_Quantity.setText(String.valueOf(v.getQuantity()));

      // Action button "Cancel"
      butCancel.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              dispose();
            }
          });

      // Action button "OK"
      butOk.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              if (shop != null) {
                try {
                  String n = text_Name.getText();
                  String proiz = text_Proizvod.getText();
                  int pric = Integer.parseInt(text_Price.getText());
                  int quant = Integer.parseInt(text_Quantity.getText());

                  VideoTechnik vid = new VideoTechnik(n, proiz, pric, quant);

                  vid.setShop(shop);

                  shop.removeVideoTechnik(v);
                  shop.addVideoTechnik(vid);
                  listBefore.setListData(shop.getVideoTechnik().toArray());
                  label2.setText("Количество наименований: " + shop.getVideoTechnik().size());
                  dispose();
                } catch (NumberFormatException ex) {
                  JOptionPane.showMessageDialog(
                      panel5, "Неправильный формат!!!\nPlease, try again.");
                } catch (VideoTechnikException ee) {
                  JOptionPane.showMessageDialog(panel5, ee.getMessage());
                }
              }
            }
          });
      this.setVisible(true);
    }
Пример #4
0
 public String poisk(String str, int chans) {
   String s = "";
   int j = 1;
   for (int k = 0; k < this.videoTechnik.size(); k++) {
     VideoTechnik v = (VideoTechnik) this.videoTechnik.get(k);
     switch (chans) {
       case 1:
         {
           if ((v.getName()).equals(str)) {
             s =
                 s
                     + "Название: "
                     + v.getName()
                     + "   Производитель: "
                     + v.getProizvod()
                     + "\nЦена: "
                     + v.getPrice()
                     + "   Количество: "
                     + v.getQuantity()
                     + "\n";
           }
         }
         break;
       case 2:
         {
           if ((v.getProizvod()).equals(str)) {
             s =
                 s
                     + (j++)
                     + ") Название: "
                     + v.getName()
                     + "\nЦена: "
                     + v.getPrice()
                     + "   Количество: "
                     + v.getQuantity()
                     + "\n";
           }
         }
         break;
       case 3:
         {
           if ((v.getPrice()) <= (Integer.parseInt(str))) {
             s =
                 s
                     + (j++)
                     + ") Название: "
                     + v.getName()
                     + "   Производитель: "
                     + v.getProizvod()
                     + "\nЦена: "
                     + v.getPrice()
                     + "   Количество: "
                     + v.getQuantity()
                     + "\n";
           }
         }
         break;
       case 4:
         {
           if ((v.getQuantity()) <= (Integer.parseInt(str))) {
             s =
                 s
                     + (j++)
                     + ") Название: "
                     + v.getName()
                     + "   Производитель: "
                     + v.getProizvod()
                     + "\nЦена: "
                     + v.getPrice()
                     + "   Количество: "
                     + v.getQuantity()
                     + "\n";
           }
         }
         break;
     }
   }
   return s;
 }
Пример #5
0
    public void actionPerformed(ActionEvent e) {
      if (listBefore.getSelectedValue() != null) {
        try {
          VideoTechnik v = (VideoTechnik) listBefore.getSelectedValue();
          String str = JOptionPane.showInputDialog(panel5, "Количество: ");

          String nam = v.getName();
          String proiz = v.getProizvod();
          int pric = v.getPrice();
          int quan = Integer.parseInt(str);
          VideoTechnik vid = new VideoTechnik(nam, proiz, pric, quan);

          Calendar calend = Calendar.getInstance();
          String am_pm = "";

          if (Integer.parseInt(str) > v.getQuantity()) {
            JOptionPane.showMessageDialog(panel5, "Нет в наличии " + str + " VideoTechnik");
          } else if (v.getQuantity() == Integer.parseInt(str)) {
            shop.removeVideoTechnik(v);
            if (calend.get(Calendar.AM_PM) == 0) {
              am_pm = "PM";
            } else am_pm = "AM";
            if (calend.get(Calendar.MONTH) <= 9) {
              prodanVideo.add(
                  String.valueOf(
                          (calend.get(Calendar.DATE)
                                  + "."
                                  + ("0" + (1 + calend.get(Calendar.MONTH)))
                                  + " ")
                              + (7 + calend.get(Calendar.HOUR))
                              + ":"
                              + calend.get(Calendar.MINUTE)
                              + " "
                              + am_pm)
                      + " - "
                      + vid);
            } else
              prodanVideo.add(
                  String.valueOf(
                          (calend.get(Calendar.DATE) + "." + (1 + calend.get(Calendar.MONTH)) + " ")
                              + (7 + calend.get(Calendar.HOUR))
                              + ":"
                              + calend.get(Calendar.MINUTE)
                              + " "
                              + am_pm)
                      + " - "
                      + vid);
          } else if (v.getQuantity() != Integer.parseInt(str)) {
            v.toBuy(Integer.parseInt(str));
            if (calend.get(Calendar.AM_PM) == 0) am_pm = "PM";
            else am_pm = "AM";
            if (calend.get(Calendar.MONTH) <= 9) {
              prodanVideo.add(
                  String.valueOf(
                          (calend.get(Calendar.DATE)
                                  + "."
                                  + ("0" + (1 + calend.get(Calendar.MONTH)))
                                  + " ")
                              + (7 + calend.get(Calendar.HOUR))
                              + ":"
                              + calend.get(Calendar.MINUTE)
                              + " "
                              + am_pm)
                      + " - "
                      + vid);
            } else
              prodanVideo.add(
                  String.valueOf(
                          (calend.get(Calendar.DATE) + "." + (1 + calend.get(Calendar.MONTH)) + " ")
                              + (7 + calend.get(Calendar.HOUR))
                              + ":"
                              + calend.get(Calendar.MINUTE)
                              + " "
                              + am_pm)
                      + " - "
                      + vid);
          }

          listAfter.setListData(prodanVideo.toArray());
          // textQuantity.setText(String.valueOf(v.getQuantity()));
          listBefore.setListData(shop.getVideoTechnik().toArray());
          label2.setText("Количество наименований: " + shop.getVideoTechnik().size());

        } catch (VideoTechnikException a) {
          JOptionPane.showMessageDialog(panel5, a.getMessage());
        } catch (NumberFormatException a) {
        } catch (NullPointerException aa) {
        }
      } else
        JOptionPane.showMessageDialog(panel5, "Не выбрана VideoTechnik!!!\nPlease, try again.");
    }