S

spike_55

Usuario (México)

Primer post: 7 ene 2011Último post: 7 ene 2011
2
Posts
0
Puntos totales
5
Comentarios
como crear un programa que te de tu RFC
como crear un programa que te de tu RFC
InfoporAnónimo1/7/2011

Bueno aqui les dejo un programa que hise para que te dieran el RFC poniendo tus datos: Primero debes abrir una hoja con el titulo Persona por ejemplo y pones este codigo: class Persona { public String nombre; private String apePat; private String apeMat; private int añoNac; private int mesNac; private int diaNac; private int diaAct; private int mesAct; private int añoAct; private int edad; private String rfc; public void setNombre(String nombre){ this.nombre=nombre; } public String getNombre(){ return nombre; } public void setApePat ( String apePat){ this.apePat=apePat; } public String getApePat (){ return apePat; } public void setApeMat(String apeMat){ this.apeMat=apeMat; } public String getApeMat (){ return apeMat; } public void setDiaNac (int diaNac){ this.diaNac=diaNac; } public int getDiaNac(){ return diaNac; } public void setMesNac(int mesNac){ this.mesNac=mesNac; } public int getMesNac(){ return mesNac; } public void setAñoNac(int añoNac){ this.añoNac=añoNac; } public int getAñoNac(){ return añoNac; } public void setDiaAct(int diaAct){ this.diaAct=diaAct; } public int getDiaAct(){ return diaAct; } public void setMesAct(int mesAct){ this.mesAct=mesAct; } public int getMesAct(){ return mesAct; } public void setAñoAct(int añoAct){ this.añoAct=añoAct; } public int getAñoAct(){ Luego abres otra hoja la cual le pondras de nombre MainPersona y le pones este codigo: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.String.*; public class MainPersona extends JFrame{ int cont=0; String edadC; Persona []p=new Persona[5]; JPanel panel0=new JPanel(new GridLayout(2,1)) ; JPanel panel1=new JPanel(new GridLayout(11,2)) ; JPanel panel2=new JPanel(new GridLayout(1,5)) ; JLabel label1=new JLabel("Teclea tu Nombre: " ) ; JLabel label2=new JLabel("Teclea tu Apellido Paterno: " ) ; JLabel label3=new JLabel("Teclea tu Apellido Materno: " ) ; JLabel label4=new JLabel("Dia de nacimiento (dos digitos) : " ) ; JLabel label5=new JLabel("Mes de nacimiento (dos digitos) : " ) ; JLabel label6=new JLabel("Año de nacimiento (cuatro digitos) : " ) ; JLabel label7=new JLabel("El dia de hoy(dos digitos: ) " ) ; JLabel label8=new JLabel("El mes en el que estamos(dos digistos) : " ) ; JLabel label9=new JLabel("El año en el que te encuentras(cuatro digitos) : " ) ; JLabel label10=new JLabel("Esta es tu edad : " ) ; JLabel label11=new JLabel("Este es tu RFC : " ) ; JTextField text1=new JTextField() ; JTextField text2=new JTextField() ; JTextField text3=new JTextField() ; JTextField text4=new JTextField() ; JTextField text5=new JTextField() ; JTextField text6=new JTextField() ; JTextField text7=new JTextField() ; JTextField text8=new JTextField() ; JTextField text9=new JTextField() ; JTextField text10=new JTextField() ; JTextField text11=new JTextField() ; JButton butE= new JButton("Cal edad" ) ; JButton butC= new JButton("Cal RFC" ) ; JButton butG= new JButton("Guardar" ) ; JButton butL= new JButton("Limpiar" ) ; JButton butR= new JButton("Reporte" ) ; JButton butS= new JButton("Salir" ) ; public MainPersona(){ super ("Datos Personales" ) ; this.setSize(500,700 ) ; this.setResizable(false) ; this.setVisible(true) ; this.setDefaultCloseOperation(EXIT_ON_CLOSE) ; getContentPane().add(panel0) ; panel0.setBorder(BorderFactory.createEmptyBorder(2,2,2,2 ) ) ; panel0.add(panel1) ; panel0.add(panel2) ; panel1.add(label1) ; panel1.add(text1) ; panel1.add(label2) ; panel1.add(text2) ; panel1.add(label3) ; panel1.add(text3) ; panel1.add(label4) ; panel1.add(text4) ; panel1.add(label5) ; panel1.add(text5) ; panel1.add(label6) ; panel1.add(text6) ; panel1.add(label7) ; panel1.add(text7) ; panel1.add(label8) ; panel1.add(text8) ; panel1.add(label9) ; panel1.add(text9) ; panel1.add(label10) ; panel1.add(text10) ; panel1.add(label11) ; panel1.add(text11) ; text10.setEditable(true) ; text11.setEditable(true) ; panel2.add(butG) ; panel2.add(butE) ; panel2.add(butC) ; panel2.add(butL) ; panel2.add(butR) ; panel2.add(butS) ; butE.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { for(int i=0; i<cont; i++){ text10.setText(p.calcEdad()+ "" ); /*p.setDiaNac(Integer.parseInt(text4.getText( ) ) ) ; p.setMesNac(Integer.parseInt(text5.getText( ) ) ) ; p.setAñoNac(Integer.parseInt(text6.getText( ) ) ) ; p.setDiaAct(Integer.parseInt(text7.getText( ) ) ) ; p.setMesAct(Integer.parseInt(text8.getText( ) ) ) ; p.setAñoAct(Integer.parseInt(text9.getText( ) ) ) ; //edad=p[0].calcEdad() ; // String edadC=edad+"" ; text11.setText(p.calcEdad()+"" ) ; text10.setText(edadC) ; //text11.setText(edadC) ; * / } } }); butC.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String N="" ; String P="" ; String Ma="" ; String D="" ; String M="" ; String A="" ; String rfc= "" ; N=new String (text1.getText() ) ; P=new String (text2.getText() ) ; Ma=new String (text3.getText() ) ; D=new String (text4.getText() ) ; M=new String (text5.getText() ) ; A=new String (text6.getText() ) ; N=N.substring(0,1) ; System.out.println("N: "+N) ; P=P.substring(0,2) ; System.out.println("P: "+P) ; Ma=Ma.substring(0,1) ; System.out.println("Ma: "+Ma) ; D=D.substring(0,2) ; System.out.println("D: "+D) ; M=M.substring(0,2) ; System.out.println("M: "+M) ; A=A.substring(2,4) ; System.out.println("A: "+A) ; rfc=P+Ma+N+A+M+D; text11.setText(rfc.toUpperCase()+" " ) ; p[cont-1].setRfc(rfc) ; } }) ; butG.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ p[cont]=new Persona(); p[cont].setNombre(text1.getText() ) ; p[cont].setApePat(text2.getText() ) ; p[cont].setApeMat(text3.getText() ) ; p[cont].setDiaNac(Integer.parseInt(text4.getText() ) ) ; p[cont].setMesNac(Integer.parseInt(text5.getText() ) ) ; p[cont].setAñoNac(Integer.parseInt(text6.getText() ) ) ; p[cont].setDiaAct(Integer.parseInt(text7.getText() ) ) ; p[cont].setMesAct(Integer.parseInt(text8.getText() ) ) ; p[cont].setAñoAct(Integer.parseInt(text9.getText() ) ) ; //p[cont].calcEdad(Integer.parseInt(text10.getText() ) ) ; p[cont].setRfc(text11.getText() ) ; cont++; } } ) ; butL.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ text1.setText( "" ) ; text2.setText( "" ) ; text3.setText( "" ) ; text4.setText( "" ) ; text5.setText( "" ) ; text6.setText( "" ) ; text7.setText( "" ) ; text8.setText( "" ) ; text9.setText( "" ) ; text10.setText( "" ) ; text11.setText( "" ) ; } } ) ; butR.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String cad="Nombre ApellidoP ApellidoM DiaN MesN AñoN DiaP MesP AñoP Edad RFCn"; for(int i=0; i<cont; i++){ cad=cad+p.getNombre()+" "+p.getApePat() +" "+p.getApeMat()+" "+p.getDiaNac() +" "+p.getMesNac()+" "+p.getAñoNac()+" " +p.getDiaAct()+" "+p.getMesAct()+" "+p.getAñoAct() +" "+p.calcEdad()+" "+p.getRfc()+ "n"; } JOptionPane.showMessageDialog(null,cad,"Reporte",JOptionPane.INFORMATION_MESSAGE); } } ) ; butS.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); } } ) ; } public static void main (String args[]){ MainPersona mc=new MainPersona(); } } Nota:Esto esta hecho en el programa de GEL. Aparte hay ; ( y "" que estan separadas eso es por causa de los emoticones les recomiendo que los junten porque cuando quieres depurar el programa puede que por estos te marque errores. Espero y les sirva el codigo

0
5
como crear una calculadora en AWT y en APPLET
como crear una calculadora en AWT y en APPLET
InfoporAnónimo1/7/2011

aki les dejo unos codigos para los que les dejan trabajos escolares de crear una calculadora usando java o visual basic espero y les sea de ayuda saludos... primero el AWT Import java. Awt. *; import java.awt.event. *; public class Calculadora extends Frame { Button bn[]=new Button[10]; Button bn2[]=new Button[4]; Button igual=new Button("=" ) ; TextField txt1=new TextField() ; int num1=0; char ope; public Calculadora() { setLayout(new FlowLayout()) ; int i=0; for (i=0;i<bn. Length;i++) { bn=new Button(String. ValueOf(i+1)) ; bn. AddActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { escribirNumero(e) ; } }) ; add(bn) ; } for (i=0;i<bn2. Length;i++) { bn2=new Button() ; switch(i) { case 0: bn2. SetLabel("+" ) ; break; case 1: bn2. SetLabel("*" ) ; break; case 2: bn2. SetLabel("-" ) ; break; case 3: bn2. SetLabel("/" ) ; break; } bn2. AddActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { almacenarOperador(e) ; } }) ; add(bn2) ; } igual. AddActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mostrarResultado(e) ; } }) ; add(igual) ; add(txt1) ; } public void escribirNumero(ActionEvent e) { Button boton=(Button)(e. GetSource()) ; txt1. SetText(txt1. GetText()+boton. GetLabel()) ; } public void almacenarOperador(ActionEvent e) { Button boton=(Button)(e. GetSource()) ; ope=boton. GetLabel(). CharAt(0) ; num1=Integer. ParseInt(txt1. GetText()) ; txt1. SetText( "" ) ; } public void mostrarResultado(ActionEvent e) { int num2=Integer. ParseInt(txt1. GetText()) ; int res=0; switch (ope) { case '+': res=num1+num2; break; case '-': res=num1-num2; break; case '*': res=num1*num2; break; case '/': res=num1/num2; break; } txt1. SetText(String. ValueOf(res)) ; } public static void main (String args[]) { Calculadora c=new Calculadora() ; c. SetVisible(true) ; } } segudo el APPLET Import java. Util. *; import java. Awt. *; import java. Applet. *; /** * Calculadora sencilla */ public class Calc extends Applet { Display display = new Display() ; /** * inicializa el applet Calc */ public void init () { SetLayout(new BorderLayout()) ; Keypad keypad = new Keypad() ; Add ("North", display) ; add ("Center", keypad) ; } /** * manipulador para las funciones de la calculadora. */ public boolean action (Event ev, Object arg) { If (ev. Target instanceof Button) { String label = (String)arg; if (label. Equals("C" )) { display. Clear () ; return true; } else if (label. Equals(". " )) { display. Dot () ; return true; } else if (label. Equals("+" )) { display. Plus () ; return true; } else if (label. Equals("-" )) { display. Minus () ; return true; } else if (label. Equals("x" )) { display. Mul () ; return true; } else if (label. Equals("/" )) { display. Div () ; return true; } else if (label. Equals("+/-" )) { display. Chs () ; return true; } else if (label. Equals("=" )) { display. Equals () ; return true; } else { display. Digit (label) ; return true; } } return false; } /** * Esto permite que la clase se use como applet o como aplicación independiente */ public static void main (String args[]) { Frame f = new Frame ("Calculator" ) ; Calc calc = new Calc (); Calc. Init () ; f. Resize (210, 200) ; f. Add ("Center", calc) ; f. Show () ; } } /* -------------------------------------------------- */ /** * Keypad manipula la entrada de datos y la visualización de resultados */ class Keypad extends Panel { /** * inicializa keypad, añade los botones, establece los colores, etc. */ Keypad (){ Button b = new Button() ; Font font = new Font ("Times", Font. BOLD, 14) ; Color functionColor = new Color (255, 255, 0) ; Color numberColor = new Color (0, 255, 255) ; Color equalsColor = new Color (0, 255, 0) ; setFont (font) ; b. SetForeground (Color. Black) ; Add (b = new Button ("7" )) ; b. SetBackground (numberColor) ; add (b = new Button ("8") ; b. SetBackground (numberColor) ; add (b = new Button ("9" )) ; b. SetBackground (numberColor) ; add (b = new Button ("/" )) ; b. SetBackground (functionColor) ; Add (b = new Button ("4" )) ; b. SetBackground (numberColor) ; add (b = new Button ("5" )) ; b. SetBackground (numberColor) ; add (b = new Button ("6" )) ; b. SetBackground (numberColor) ; add (b = new Button ("x" )) ; b. SetBackground (functionColor) ; Add (b = new Button ("1" )) ; b. SetBackground (numberColor) ; add (b = new Button ("2" )) ; b. SetBackground (numberColor) ; add (b = new Button ("3" )) ; b. SetBackground (numberColor) ; add (b = new Button ("-" )) ; b. SetBackground (functionColor) ; Add (b = new Button (". " )) ; b. SetBackground (functionColor) ; add (b = new Button ("0" )) ; b. SetBackground (numberColor) ; add (b = new Button ("+/-" )) ; b. SetBackground (functionColor) ; add (b = new Button ("+" )) ; b. SetBackground (functionColor) ; Add (b = new Button ("C" )) ; b. SetBackground (functionColor) ; add (new Label ("" )) ; add (new Label ("" )) ; add (b = new Button ("=" )) ; b. SetBackground (equalsColor) ; SetLayout (new GridLayout (5, 4, 4, 4)) ; } } /* -------------------------------------------------- */ /** * la clase Display gestiona la visualización del resultado calculado y también * implementa las tecla de fucnión de la calculadora */ class Display extends Panel{ Double last = 0; int op = 0; boolean equals = false; int maxlen = 10; String s; Label readout = new Label("" ) ; /** * Inicializa display */ Display () { SetLayout(new BorderLayout()) ; setBackground (Color. Red) ; setFont (new Font ("Courier", Font. BOLD + Font. ITALIC, 30)) ; readout. SetAlignment(1) ; add ("Center",readout) ; repaint() ; Clear () ; } /** * manipulación del pulsado de un dígito */ void Digit (String digit) { checkEquals () ; /* * quita los ceros precedentes */ if (s. Length () == 1 && s. CharAt (0) == '0' && digit. CharAt (0)! = '. ') s = s. Substring (1) ; If (s. Length () < maxlen) s = s + digit; showacc () ; } /** * manipulación del punto decimal */ void Dot () { checkEquals () ; /* * ya tiene un '.' */ if (s. IndexOf ('. ')! = -1) return; If (s. Length () < maxlen) s = s + ". "; showacc () ; } /** * si el usuario pulsa = sin haber pulsado antes un operador * (+,-,x,/), pone cero en la visualización */ private void checkEquals () { if (equals == true) { equals = false; s = "0"; } } /** * operador suma para uso posterior. */ void Plus () { op = 1; operation () ; } /** * operador resta para uso posterior. */ void Minus () { op = 2; operation () ; } /** * operador multiplicación para uso posterior. */ void Mul () { op = 3; operation () ; } /** * operador división para uso posterior. */ void Div () { op = 4; operation () ; } /** * Interpreta el valor de la visualización como double y lo almacena * para uso posterior */ private void operation () { if (s. Length () == 0) return; Double xyz = Double. ValueOf (s) ; last = xyz. DoubleValue () ; Equals = false; s = "0"; } /** * invalida el valor actual y revisualiza. */ void Chs () { if (s. Length () == 0) return; If (s. CharAt (0) == '-') s = s. Substring (1) ; else s = "-" + s; Showacc () ; } /** * termina el último cálculo y visualiza el resultado */ void Equals () { double acc; If (s. Length () == 0) return; Double xyz = Double. ValueOf (s) ; switch (op) { case 1: acc = last + xyz. DoubleValue () ; break; Case 2: acc = last - xyz. DoubleValue () ; break; Case 3: acc = last * xyz. DoubleValue () ; break; Case 4: acc = last / xyz. DoubleValue () ; break; Default: acc = 0; break; } S = new Double (acc). ToString () ; showacc () ; equals = true; last = 0; op = 0; } /** * limpia la visualización y el último valor interno */ void Clear () { last = 0; op = 0; s = "0"; equals = false; showacc () ; } /** * pide que se repinte el resultado */ private void showacc () { readout. SetText(s) ; repaint () ; } } NOTA: los punto y coma y las entre comillas van juntos de los parentesis pero yo los separe xk m ponen los emoticones

0
6
PosteameloArchivo Histórico de Taringa! (2004-2017). Preservando la inteligencia colectiva de la internet hispanohablante.

CONTACTO

18 de Septiembre 455, Casilla 52

Chillán, Región de Ñuble, Chile

Solo correo postal

© 2026 Posteamelo.com. No afiliado con Taringa! ni sus sucesores.

Contenido preservado con fines históricos y culturales.