diegoak
Desconectado
Mensajes: 21
Mente abierta... siempre aprendiendo
|
Bueno ya pude hacerlo yo por mi cuenta hehe, lo hice en el jbuilder asi que por eso esta un poco extens de mas [es el ejemplo de una chequera] ahi les va:
package chequera;
import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.borland.jbcl.layout.*;
/** * <p>Título: </p> * <p>Descripción: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Empresa: </p> * @author sin atribuir * @version 1.0 */
public class Chequera extends JFrame { JPanel contentPane; XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JLabel jLabel5 = new JLabel(); JTextArea jTextArea1 = new JTextArea(); JButton jButton1 = new JButton(); JTextField jTextField1 = new JTextField(); JTextField jTextField2 = new JTextField(); JTextField jTextField3 = new JTextField(); JTextField jTextField4 = new JTextField(); JLabel jLabel6 = new JLabel(); JButton jButton2 = new JButton(); //Construir el marco public Chequera() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } }
//Inicialización de componentes private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); jLabel1.setText("Banco HSBC"); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(530, 365)); this.setTitle("Chequera"); jLabel2.setText("Fecha:"); jLabel3.setText("Paguese a Nombre de:"); jLabel4.setText("La cantidad de:"); jLabel5.setHorizontalAlignment(SwingConstants.LEFT); jLabel5.setText("Son:"); jLabel5.setVerticalAlignment(javax.swing.SwingConstants.CENTER); jButton1.setText("Procesar"); jButton1.addActionListener(new Chequera_jButton1_actionAdapter(this)); jTextField2.setText(""); jTextField1.setText(""); jTextField3.setText(""); jTextField4.setText(""); jTextArea1.setText(""); jLabel6.setVerticalAlignment(javax.swing.SwingConstants.CENTER); jLabel6.setText("00/100 M.N"); jLabel6.setHorizontalAlignment(SwingConstants.LEFT); jButton2.setText("Limpiar"); jButton2.addActionListener(new Chequera_jButton2_actionAdapter(this)); contentPane.add(jTextArea1, new XYConstraints(9, 189, 510, 165)); contentPane.add(jButton1, new XYConstraints(162, 144, 81, 26)); contentPane.add(jButton2, new XYConstraints(271, 144, 81, 26)); contentPane.add(jLabel1, new XYConstraints(198, 2, 68, 25)); contentPane.add(jLabel3, new XYConstraints(45, 59, 111, 19)); contentPane.add(jLabel4, new XYConstraints(45, 85, 81, 19)); contentPane.add(jLabel5, new XYConstraints(45, 110, 27, 19)); contentPane.add(jTextField2, new XYConstraints(155, 59, 248, 19)); contentPane.add(jTextField3, new XYConstraints(120, 85, 66, 19)); contentPane.add(jTextField4, new XYConstraints(68, 110, 322, 19)); contentPane.add(jLabel6, new XYConstraints(394, 110, 61, 19)); contentPane.add(jTextField1, new XYConstraints(399, 27, 56, 19)); contentPane.add(jLabel2, new XYConstraints(364, 27, 34, 19)); jTextArea1.setText(" BANCO HSBC"+"\n"+"\n"+ " FECHA:______"+"\n"+"\n"+ " Paguese a nombre de:____________________________________________"+"\n"+"\n"+ " La cantidad de:_________________________________________________"+"\n"+"\n"+ " Son:_________________________________________________ 00/100 M.N"); }
//Modificado para poder salir cuando se cierra la ventana protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } }
void jButton1_actionPerformed(ActionEvent e) { String fecha,nombre,cantidad,lu,ld,lc,lum,ldm,lcm; int u,d,c,um,dm,cm,cant; fecha=jTextField1.getText(); nombre=jTextField2.getText(); cant=Integer.parseInt(jTextField3.getText()); if (cant<10 && cant>=0) jTextField3.setText("00000"+cant); if (cant<=99 && cant>=10) jTextField3.setText("0000"+cant); if (cant<=999 &&cant >=100) jTextField3.setText("000"+cant); if (cant<=9999 && cant>=1000) jTextField3.setText("00"+cant); if (cant<=99999 && cant>=10000) jTextField3.setText("0"+cant); cantidad=jTextField3.getText();
u=Integer.parseInt(cantidad.substring(5,6)); d=Integer.parseInt(cantidad.substring(4,5)); c=Integer.parseInt(cantidad.substring(3,4)); um=Integer.parseInt(cantidad.substring(2,3)); dm=Integer.parseInt(cantidad.substring(1,2)); cm=Integer.parseInt(cantidad.substring(0,1)); switch(u){ case 0: lu="";break; case 1: lu="un";break; case 2: lu="dos";break; case 3: lu="tres";break; case 4: lu="cuatro";break; case 5: lu="cinco";break; case 6: lu="seis";break; case 7: lu="siete";break; case 8: lu="ocho";break; case 9: lu="nueve";break; default: lu="error"; } switch(d){ case 0: ld="";break; case 1: ld="";if (u==0)lu="diez";if(u==1)lu="once";if(u==2)lu="doce";if(u==3)lu="trece";if(u==4)lu="catorce";if(u==5)lu="quince"; if(u==6)lu="dieciseis";if(u==7)lu="diecisiete";if(u==8)lu="dieciocho";if(u==9)lu="diecinueve";break; case 2: if(u==0)ld="veinte";else ld="veinti";break; case 3: if(u==0)ld="treinta";else ld="treinta y ";break; case 4: if(u==0)ld="cuarenta";else ld="cuarenta y ";break; case 5: if(u==0)ld="cincuenta";else ld="cincuenta y ";break; case 6: if(u==0)ld="sesenta";else ld="sesnta y ";break; case 7: if(u==0)ld="setenta";else ld="setenta y ";break; case 8: if(u==0)ld="ochenta";else ld="ochenta y ";break; case 9: if(u==0)ld="noventa";else ld="noventa y ";break; default: ld="error"; } switch(c){ case 0: lc="";break; case 1: { if (d==0 && u==0) lc="cien"; else lc="ciento ";break;} case 2: lc="doscientos ";break; case 3: lc="trescientos ";break; case 4: lc="cuatrocientos ";break; case 5: lc="quinientos ";break; case 6: lc="seiscientos ";break; case 7: lc="setecientos ";break; case 8: lc="ochocientos ";break; case 9: lc="novecientos ";break; default: lc="error";}
switch(um){ case 0: lum="";if(dm>0)lum="mil ";if(cm>0)lum="mil ";break; case 1: lum="unmil ";break; case 2: lum="dosmil ";break; case 3: lum="tresmil ";break; case 4: lum="cuatromil ";break; case 5: lum="cincomil ";break; case 6: lum="seismil ";break; case 7: lum="sietemil ";break; case 8: lum="ochomil ";break; case 9: lum="nuevemil ";break; default: lum="error";} switch(dm){ case 0: ldm="";break; case 1: ldm="";if(um==0)lum="diez mil ";if(um==1)lum="once mil ";if(um==2)lum="doce mil "; if(um==3)lum="trece mil ";if(um==4)lum="catorce mil ";if(um==5)lum="quince mil "; if(um==6)lum="dieciseis mil ";if(um==7)lum="diecisiete mil ";if(um==8)lum="dieciocho mil "; if(um==9)lum="diecinueve mil ";break; case 2: if(u==0)ldm="veinte";else ldm="veinti ";break; case 3: if(um==0)ldm="treinta";else ldm="treinta y ";break; case 4: if(um==0)ldm="cuarenta";else ldm="cuarenta y ";break; case 5: if(um==0)ldm="cincuenta";else ldm="cincuenta y ";break; case 6: if(um==0)ldm="sesenta";else ldm="sesenta y ";break; case 7: if(um==0)ldm="setenta";else ldm="setenta y ";break; case 8: if(um==0)ldm="ochenta";else ldm="ochenta y ";break; case 9: if(um==0)ldm="noventa";else ldm="noventa y ";break; default: ldm="error"; } switch(cm){ case 0: lcm="";break; case 1: { if (dm==0 && um==0) lcm="Cien "; else lcm="Ciento ";break;} case 2: lcm="Doscientos ";break; case 3: lcm="Trescientos ";break; case 4: lcm="Cuatrocientos ";break; case 5: lcm="Quinientos ";break; case 6: lcm="Seiscientos ";break; case 7: lcm="Setecientos ";break; case 8: lcm="Ochocientos ";break; case 9: lcm="Novecientos ";break; default: lcm="error";} if (cant<10 && cant>=0) jTextField3.setText(""+cant); if (cant<=99 && cant>=10) jTextField3.setText(""+cant); if (cant<=999 &&cant >=100) jTextField3.setText(""+cant); if (cant<=9999 && cant>=1000) jTextField3.setText(""+cant); if (cant<=99999 && cant>=10000) jTextField3.setText(""+cant); cantidad=jTextField3.getText();
jTextArea1.setText(" BANCO HSBC"+"\n"+"\n"+ " FECHA:"+fecha+ "\n"+"\n"+" Paguese a nombre de: "+nombre+"\n"+"\n"+ " La cantidad de: $"+cantidad+"\n"+"\n"+ " Son: "+lcm+ldm+lum+lc+ld+lu+" 00/100 M.N"); jTextField4.setText(lcm+ldm+lum+lc+ld+lu); }
public void jButton2_actionPerformed(ActionEvent e) { jTextField1.setText(" "); jTextField2.setText(" "); jTextField3.setText(""); jTextField4.setText(" "); jTextArea1.setText(" BANCO HSBC"+"\n"+"\n"+ " FECHA:______"+"\n"+"\n"+ " Paguese a nombre de:____________________________________________"+"\n"+"\n"+ " La cantidad de:_________________________________________________"+"\n"+"\n"+ " Son:__________________________________________________00/100 M.N"); } }
class Chequera_jButton2_actionAdapter implements ActionListener { private Chequera adaptee; Chequera_jButton2_actionAdapter(Chequera adaptee) { this.adaptee = adaptee; }
public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); } }
class Chequera_jButton1_actionAdapter implements java.awt.event.ActionListener { Chequera adaptee;
Chequera_jButton1_actionAdapter(Chequera adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); } }
|