Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
MyBancoCredito - Framemodulo.java

Framemodulo.java

Caricato da: Bonny
Scarica il programma completo

  1. package jcredito;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.util.*;
  7. import javax.swing.*;
  8.  
  9. public class Framemodulo extends JFrame implements ActionListener {
  10.    
  11.     private Choice combo = new Choice();
  12.     private Choice comboday = new Choice();
  13.     private Choice combomese = new Choice();
  14.     private Choice comboanno = new Choice();
  15.     private JButton save = new JButton("Save");
  16.     private JButton delete = new JButton("Delete Accaunt");
  17.     private JButton conto = new JButton("Estratto conto");
  18.     private JPanel pdata = new JPanel();
  19.     private JPanel p = new JPanel();
  20.     private JPanel ps = new JPanel();
  21.     private JTextField credito = new JTextField();
  22.     private JTextField descri = new JTextField();
  23.     private String user = "";
  24.     private Jdbmanager jdb;
  25.     private Order odr;
  26.  
  27.     public Framemodulo(String x) {
  28.         super("Modulo");
  29.         this.user = x;
  30.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.         initCombo();
  32.         pdata.setBackground(new Color(0, 60, 120));
  33.         JLabel l0 = new JLabel(" Data:");
  34.         l0.setFont(new Font("Arial", Font.BOLD, 14));
  35.         l0.setForeground(Color.ORANGE);
  36.         pdata.add(l0);
  37.         pdata.add(comboday);
  38.         pdata.add(combomese);
  39.         pdata.add(comboanno);
  40.         p.setBackground(new Color(0, 60, 120));
  41.         p.setLayout(new GridLayout(3, 2, 10, 7));
  42.         JLabel l1 = new JLabel(" Importo:");
  43.         l1.setFont(new Font("Arial", Font.BOLD, 14));
  44.         l1.setForeground(Color.ORANGE);
  45.         p.add(l1);
  46.         p.add(credito);
  47.         JLabel l2 = new JLabel(" Tipo:");
  48.         l2.setFont(new Font("Arial", Font.BOLD, 14));
  49.         l2.setForeground(Color.ORANGE);
  50.         p.add(l2);
  51.         p.add(combo);
  52.         JLabel l3 = new JLabel("Descrizione (opzionale):");
  53.         l3.setFont(new Font("Arial", Font.BOLD, 14));
  54.         l3.setForeground(Color.ORANGE);
  55.         p.add(l3);
  56.         p.add(descri);
  57.         ps.setBackground(new Color(0, 60, 120));
  58.         ps.add(delete);
  59.         ps.add(conto);
  60.         ps.add(save);
  61.         save.addActionListener(this);
  62.         conto.addActionListener(this);
  63.         delete.addActionListener(this);
  64.         this.getContentPane().add(pdata, "North");
  65.         this.getContentPane().add(p, "Center");
  66.         this.getContentPane().add(ps, "South");
  67.         this.setResizable(false);
  68.         this.setVisible(true);
  69.         this.setBounds(340, 200, 400, 190);
  70.         this.pack();
  71.     }
  72.  
  73.     public void initCombo() {
  74.  
  75.         int i;
  76.         combo.addItem("Versamento");
  77.         combo.addItem("Prelievo");
  78.         combo.addItem("Bonifico");
  79.         combo.addItem("Pagamento");
  80.  
  81.         for (i = 1; i < 32; i++) {
  82.             comboday.addItem(String.valueOf(i));
  83.         }
  84.         for (i = 1; i < 13; i++) {
  85.             combomese.addItem(String.valueOf(i));
  86.         }
  87.  
  88.         for (i = 2010; i < 2051; i++) {
  89.             comboanno.addItem(String.valueOf(i));
  90.         }
  91.         GregorianCalendar gc=new GregorianCalendar();
  92.         comboday.select(gc.get(Calendar.DATE) - 1);
  93.         combomese.select(gc.get(Calendar.MONTH));
  94.         i = 2010;
  95.         int j = 0;
  96.         while (i < 2051) {
  97.             if (String.valueOf(i).equals(comboanno.getItem(j))) {
  98.                 break;
  99.             }
  100.             j++;
  101.             i++;
  102.         }
  103.         comboanno.select(j);
  104.     }
  105.  
  106.     public void actionPerformed(ActionEvent e) {
  107.  
  108.         if ("Save".equals(e.getActionCommand())) {
  109.             if (!credito.getText().equals("")) {
  110.                 jdb = new Jdbmanager();
  111.                 if (jdb.upDate(this.user, comboday.getSelectedItem() + "/" + combomese.getSelectedItem() + "/" + comboanno.getSelectedItem(), Long.valueOf(credito.getText()), combo.getSelectedItem(), descri.getText())) {
  112.                     JOptionPane.showMessageDialog(null, "Operazione eseguita con successo!", "msg", JOptionPane.INFORMATION_MESSAGE);
  113.                     credito.setText("");
  114.                     descri.setText("");
  115.                 } else {
  116.                     JOptionPane.showMessageDialog(null, "Errore durante il salvataggio dei dati.", "msg", JOptionPane.WARNING_MESSAGE);
  117.                 }
  118.             }else{
  119.             JOptionPane.showMessageDialog(null, "Devi Inserire l'importo.", "msg", JOptionPane.INFORMATION_MESSAGE);
  120.             }
  121.         }else if("Delete Accaunt".equals(e.getActionCommand())){
  122.            int x = JOptionPane.showConfirmDialog(null, "Sei sicuro di voler eliminare il tuo accaunt?", "msg", JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
  123.            if(x==0){
  124.                jdb = new Jdbmanager();
  125.                if(jdb.delete(user)){
  126.                    JOptionPane.showMessageDialog(null, "Operazione eseguita con successo!\n Grazie e arrivederci.", "msg", JOptionPane.INFORMATION_MESSAGE);
  127.                    System.exit(0);
  128.                }else{
  129.                    JOptionPane.showMessageDialog(null, "Errore durante l' update dei dati.", "msg", JOptionPane.WARNING_MESSAGE);
  130.                }
  131.            }
  132.         }else if("Estratto conto".equals(e.getActionCommand())){
  133.             setVisible(false);
  134.             odr = new Order(user);
  135.         }
  136.     }
  137. }