
import javax.swing.Icon;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
 */

/**
 *
 * @author mateo
 */
public class Main extends javax.swing.JFrame {

    /**
     * Creates new form Main
     */
    public double cena = 1;
    public String iconPath = "/pocztowka.png";
    
    public Main() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rodzajGroup = new javax.swing.ButtonGroup();
        RodzajPrzesylkiPanel = new javax.swing.JPanel();
        pocztowkaRB = new javax.swing.JRadioButton();
        listRB = new javax.swing.JRadioButton();
        paczkaRB = new javax.swing.JRadioButton();
        dane = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        ulicaTF = new javax.swing.JTextField();
        kodPocztowyTF = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        Miasto = new javax.swing.JLabel();
        miastTF = new javax.swing.JTextField();
        confirmBtn = new javax.swing.JButton();
        checkPriceBtn = new javax.swing.JButton();
        icon = new javax.swing.JLabel();
        cenaLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Nadaj przesylke 312312355234");

        RodzajPrzesylkiPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Rodzaj przesyłki", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP));

        rodzajGroup.add(pocztowkaRB);
        pocztowkaRB.setSelected(true);
        pocztowkaRB.setText("Pocztowka");
        pocztowkaRB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pocztowkaRBActionPerformed(evt);
            }
        });

        rodzajGroup.add(listRB);
        listRB.setText("List");
        listRB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listRBActionPerformed(evt);
            }
        });

        rodzajGroup.add(paczkaRB);
        paczkaRB.setText("Paczka");
        paczkaRB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                paczkaRBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout RodzajPrzesylkiPanelLayout = new javax.swing.GroupLayout(RodzajPrzesylkiPanel);
        RodzajPrzesylkiPanel.setLayout(RodzajPrzesylkiPanelLayout);
        RodzajPrzesylkiPanelLayout.setHorizontalGroup(
            RodzajPrzesylkiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(RodzajPrzesylkiPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(RodzajPrzesylkiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pocztowkaRB)
                    .addComponent(listRB)
                    .addComponent(paczkaRB))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        RodzajPrzesylkiPanelLayout.setVerticalGroup(
            RodzajPrzesylkiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(RodzajPrzesylkiPanelLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(pocztowkaRB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(listRB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(paczkaRB)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        dane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dane adresowe", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP));

        jLabel1.setText("Ulica z numerem");

        jLabel2.setText("Kod pocztowy");

        Miasto.setText("Miasto");

        javax.swing.GroupLayout daneLayout = new javax.swing.GroupLayout(dane);
        dane.setLayout(daneLayout);
        daneLayout.setHorizontalGroup(
            daneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(daneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(daneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(daneLayout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(Miasto)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(daneLayout.createSequentialGroup()
                        .addGroup(daneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ulicaTF)
                            .addComponent(kodPocztowyTF)
                            .addComponent(miastTF)
                            .addGroup(daneLayout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addGroup(daneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2))
                                .addGap(0, 131, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        daneLayout.setVerticalGroup(
            daneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(daneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ulicaTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(kodPocztowyTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Miasto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(miastTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        confirmBtn.setText("Zatwierdź");
        confirmBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmBtnActionPerformed(evt);
            }
        });

        checkPriceBtn.setText("Sprawdz Cenę");
        checkPriceBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkPriceBtnActionPerformed(evt);
            }
        });

        icon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pocztowka.png"))); // NOI18N

        cenaLabel.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        cenaLabel.setText("Cena: 1zł");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(confirmBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(icon)
                                .addGap(18, 18, 18)
                                .addComponent(cenaLabel))
                            .addComponent(RodzajPrzesylkiPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(checkPriceBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
                        .addComponent(dane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(36, 36, 36))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(RodzajPrzesylkiPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(checkPriceBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(icon)
                            .addComponent(cenaLabel))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addComponent(confirmBtn)
                .addGap(17, 17, 17))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void pocztowkaRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pocztowkaRBActionPerformed
        // TODO add your handling code here:
        cena = 1;
        iconPath = "/pocztowka.png";
      
    }//GEN-LAST:event_pocztowkaRBActionPerformed

    private void listRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listRBActionPerformed
        // TODO add your handling code here:
        cena = 1.5;
        iconPath = "/list.png";
    }//GEN-LAST:event_listRBActionPerformed

    private void paczkaRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_paczkaRBActionPerformed
        // TODO add your handling code here:
        cena = 10;
        iconPath = "/paczka.png";
    }//GEN-LAST:event_paczkaRBActionPerformed

    private void checkPriceBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkPriceBtnActionPerformed
        // TODO add your handling code here:
        if(cena != 1.5) {
            cenaLabel.setText("Cena: " + (int)cena + " zł");
        } else {
            cenaLabel.setText("Cena: " + cena + " zł");
        }
        icon.setIcon(new javax.swing.ImageIcon(getClass().getResource(iconPath)));
    }//GEN-LAST:event_checkPriceBtnActionPerformed

    private void confirmBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmBtnActionPerformed
        // TODO add your handling code here:
        String kodPocztowy = kodPocztowyTF.getText();
        if(kodPocztowy.length() < 5 || kodPocztowy.length() > 5) {
            JOptionPane.showMessageDialog(this, "Nieprawidłowa liczba cyfr w kodzie pocztowym");
            return;
        }
        
      
        
        for(int i=0; i<kodPocztowy.length(); i++) {
            char znak = kodPocztowy.charAt(i);
            
            if(Character.isDigit(znak) == false) {
                JOptionPane.showMessageDialog(this, "Kod pocztowy powinien się składać z samych cyfr");
                return;
            }
        }
        
        JOptionPane.showMessageDialog(this, "Dane przesyłki zostały wprowadzone");
        
        return;
    }//GEN-LAST:event_confirmBtnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Miasto;
    private javax.swing.JPanel RodzajPrzesylkiPanel;
    private javax.swing.JLabel cenaLabel;
    private javax.swing.JButton checkPriceBtn;
    private javax.swing.JButton confirmBtn;
    private javax.swing.JPanel dane;
    private javax.swing.JLabel icon;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField kodPocztowyTF;
    private javax.swing.JRadioButton listRB;
    private javax.swing.JTextField miastTF;
    private javax.swing.JRadioButton paczkaRB;
    private javax.swing.JRadioButton pocztowkaRB;
    private javax.swing.ButtonGroup rodzajGroup;
    private javax.swing.JTextField ulicaTF;
    // End of variables declaration//GEN-END:variables
}
