Configurar descuento (Nicolás)
unknown
java
a year ago
5.0 kB
6
Indexable
package Proyecto; import java.awt.EventQueue; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.UIManager; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class DlgConfigurarDescuento extends JDialog implements ActionListener { private static final long serialVersionUID = 1L; private JLabel lblNewLabel; private JLabel lblA; private JLabel lblA_2; private JLabel lblMsDe; private JTextField txtDesc1; private JTextField txtDesc2; private JTextField txtDesc3; private JTextField txtDesc4; private JLabel lblNewLabel_1; private JLabel lblNewLabel_2; private JLabel lblNewLabel_3; private JLabel lblNewLabel_4; private JButton btnCancelar; private JButton btnAceptar; public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Throwable e) { e.printStackTrace(); } EventQueue.invokeLater(new Runnable() { public void run() { try { DlgConfigurarDescuento dialog = new DlgConfigurarDescuento(); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public DlgConfigurarDescuento() { setTitle("Configurar porcentajes de descuento"); setResizable(false); setModal(true); setBounds(100, 100, 444, 149); getContentPane().setLayout(null); lblNewLabel = new JLabel("1 a 5 unidades"); lblNewLabel.setBounds(10, 11, 70, 14); getContentPane().add(lblNewLabel); lblA = new JLabel("6 a 10 unidades"); lblA.setBounds(10, 36, 76, 14); getContentPane().add(lblA); lblA_2 = new JLabel("11 a 15 unidades"); lblA_2.setBounds(10, 61, 82, 14); getContentPane().add(lblA_2); lblMsDe = new JLabel("M\u00E1s de 15 unidades"); lblMsDe.setBounds(10, 86, 95, 14); getContentPane().add(lblMsDe); txtDesc1 = new JTextField(); txtDesc1.setBounds(124, 8, 86, 20); getContentPane().add(txtDesc1); txtDesc1.setColumns(10); txtDesc2 = new JTextField(); txtDesc2.setColumns(10); txtDesc2.setBounds(124, 33, 86, 20); getContentPane().add(txtDesc2); txtDesc3 = new JTextField(); txtDesc3.setColumns(10); txtDesc3.setBounds(124, 58, 86, 20); getContentPane().add(txtDesc3); txtDesc4 = new JTextField(); txtDesc4.setColumns(10); txtDesc4.setBounds(124, 83, 86, 20); getContentPane().add(txtDesc4); lblNewLabel_1 = new JLabel("%"); lblNewLabel_1.setBounds(220, 11, 11, 14); getContentPane().add(lblNewLabel_1); lblNewLabel_2 = new JLabel("%"); lblNewLabel_2.setBounds(220, 39, 11, 14); getContentPane().add(lblNewLabel_2); lblNewLabel_3 = new JLabel("%"); lblNewLabel_3.setBounds(220, 61, 11, 14); getContentPane().add(lblNewLabel_3); lblNewLabel_4 = new JLabel("%"); lblNewLabel_4.setBounds(220, 86, 11, 14); getContentPane().add(lblNewLabel_4); btnCancelar = new JButton("Cancelar"); btnCancelar.addActionListener(this); btnCancelar.setBounds(303, 32, 89, 23); getContentPane().add(btnCancelar); btnAceptar = new JButton("Aceptar"); btnAceptar.addActionListener(this); btnAceptar.setBounds(303, 7, 89, 23); getContentPane().add(btnAceptar); } public void actionPerformed(ActionEvent e) { if (e.getSource() == btnAceptar) { actionPerformedBtnAceptar(e); } if (e.getSource() == btnCancelar) { actionPerformedBtnCancelar(e); } } protected void actionPerformedBtnCancelar(ActionEvent e) { dispose(); } protected void actionPerformedBtnAceptar(ActionEvent e) { try { double porcentaje1 = Double.parseDouble(txtDesc1.getText()); double porcentaje2 = Double.parseDouble(txtDesc2.getText()); double porcentaje3 = Double.parseDouble(txtDesc3.getText()); double porcentaje4 = Double.parseDouble(txtDesc4.getText()); JOptionPane.showMessageDialog(null, "Cambio Realizado con Éxito", "Aviso", JOptionPane.INFORMATION_MESSAGE); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog(null, "Error: Ingrese un valor numérico válido", "Error", JOptionPane.ERROR_MESSAGE); } dispose(); } }
Editor is loading...
Leave a Comment