Está en la página 1de 5

Desarrollo de Aplicacin

Cdigo: package ejemplos; import java.awt.event.KeyEvent; import javax.swing.DefaultListModel; import javax.swing.JOptionPane; /** * * @author Administrador */ public class UsoControles extends javax.swing.JFrame { private DefaultListModel listar = new DefaultListModel(); private int resp = 0; public int elem1, elem2, nfi=0; public String opcion; /** Creates new form UsoControles */ public UsoControles() { initComponents(); comb2.setEnabled(false); setSize(400, 450); //setLocation(250, 250); this.setLocationRelativeTo(null); jList1.setModel(listar); } //Para validar una cadena si es nuerica private int validaNumeros(String cadena) { int cont = 0; char cad[] = cadena.toCharArray(); for (int i = 0; i < cad.length; i++) { if (cad[i] < 48 || cad[i] > 57) { cont++; }

} return cont; } private void txt1KeyPressed(java.awt.event.KeyEvent evt) { boolean conv = false; if (evt.getKeyCode() == KeyEvent.VK_ENTER) { if (txt1.getText().trim().length() == 0) { JOptionPane.showMessageDialog(this, "Digite numero", "Error", 0); txt1.setText(null); } else { // if (validaNumeros(txt1.getText()) > 0) { try { resp = Integer.parseInt(txt1.getText()); } catch (NumberFormatException ex) { conv = true; } if (conv) { JOptionPane.showMessageDialog(this, "Debe digitar numero", "Error", 0); txt1.setText(null); } else { this.getFocusOwner().transferFocus(); } } } } private void txt2KeyPressed(java.awt.event.KeyEvent evt) { // TODO add your handling code here: if (evt.getKeyCode() == KeyEvent.VK_ENTER) { this.getFocusOwner().transferFocus(); } } private void txt3KeyPressed(java.awt.event.KeyEvent evt) { // TODO add your handling code here: if (evt.getKeyCode() == KeyEvent.VK_ENTER) { this.getFocusOwner().transferFocus(); } } private void comb1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: int sb; elem1 = comb1.getSelectedIndex(); switch (elem1) { case 0: lb1.setText(""); break; case 1: sb = 2000;

lb1.setText("2000.00"); break; case 2: sb = 1400; lb1.setText("1400.00"); break; case 3: sb = 800; lb1.setText("800.00"); break; case 4: sb = 500; lb1.setText("500.00"); break; } //this.getFocusOwner().transferFocus(); } private void rb1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (rb1.isSelected()) { comb2.setEnabled(true); } opcion = "Cuenta de Ahorreos"; } private void rb2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (rb2.isSelected()) { comb2.setEnabled(false); } opcion = "Cheque"; } private void rb3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (rb3.isSelected()) { comb2.setEnabled(false); } opcion = "Efectivo"; } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: rb3.setSelected(false); rb2.setSelected(false); rb1.setSelected(false); txt1.setText(""); txt2.setText(""); txt3.setText(""); comb1.setSelectedIndex(0);

comb2.setSelectedIndex(0); comb2.setEnabled(false); lb1.setText(""); //listar.clear(); //jList1.setModel(new DefaultListModel());

} private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if ((rb2.isSelected() == true) || (rb3.isSelected() == true)) { listar.addElement(txt1.getText() + "|" + txt2.getText() + "|" + txt3.getText() + "|" + comb1.getItemAt(elem1) + "|" + lb1.getText() + "|" + opcion); } else { listar.addElement(txt1.getText() + "|" + txt2.getText() + "|" + txt3.getText() + "|" + comb1.getItemAt(elem1) + "|" + lb1.getText() + "|" + opcion + "|" + comb2.getItemAt(elem2)); } } private void comb2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: elem2 = comb2.getSelectedIndex(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new UsoControles().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JComboBox comb1; private javax.swing.JComboBox comb2; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JList jList1; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel lb1; private javax.swing.JRadioButton rb1; private javax.swing.JRadioButton rb2; private javax.swing.JRadioButton rb3; private javax.swing.JTextField txt1; private javax.swing.JTextField txt2; private javax.swing.JTextField txt3; // End of variables declaration }