elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


  Mostrar Mensajes
Páginas: [1]
1  Programación / Java / Re: ¿POR QUE NO ENTRA AL "FOR"? _ Arreglos + JAVA en: 13 Mayo 2009, 23:45 pm
HOLA ESTE MIRA PUES YO TENGO ESTE KODIGO PERO LO UNIKO que ME FALTA ES que ME LO IMPRIMA EN FORMA DE TRIANGULO ESPERO que TE AYUDE PERO SI ALGUIEN ME PUEDE DECIR KOMO SE LO AGREDASERE ATTE UNA NOVATITA EN JAVA :-\

import javax.swing.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class TrianguloPascal extends JFrame implements ActionListener
 {
    Label      et1     = new Label("De que numero: ");   
    TextField  num   = new TextField();
    Button     botonCalcular = new Button("Calcular");
    Button     botonLimpiar  = new Button("Limpiar");
   Button     botonCerrar   = new Button("Cerrar");
   TextArea resultado = new TextArea();
 public TrianguloPascal()
    {
    // Establesco el nombre en la barra de titulo
   super("---TRIANGULO DE PASCAL---");
      // Se establece que el Administrador de Aspecto sea nulo
    this.setLayout(new BorderLayout ());
     this.setLayout(null);
   
   // Establesco los parametros del TextArea

   resultado.setBackground(Color.pink);
   resultado.setFont(new Font("Tahoma",Font.PLAIN,12));
   resultado.setForeground(Color.black);// Letra del TextArea
   // Se establecen posicion y tamaño del Frame y de los componentes
    this.setBounds(220,220,700,500);//Esto es el frame
   
   et1.setBounds(20,40,120,20);
   num.setBounds(150,40,160,20);
   resultado.setBounds(50,100,590,300);
   botonCalcular.setBounds(80,450,100,30);
   botonLimpiar.setBounds(220,450,100,30);
   botonCerrar.setBounds(360,450,100,30);
   
      this.add(et1);
      this.add(num);
   
   this.add(resultado);
      this.add(botonCalcular);
      this.add(botonLimpiar);
      this.add(botonCerrar);


      botonCalcular.addActionListener(this);
      botonLimpiar.addActionListener(this);
      botonCerrar.addActionListener(this);
      
            this.show();
            
      addWindowListener(new WindowAdapter()
      {
         public void windowClosing(WindowEvent d)
          {
             System.exit(0);
          }});
      
      

    }            
   public void actionPerformed(ActionEvent ev)
   {
      if(ev.getSource() == botonCerrar)
      {
         this.dispose();
         System.exit(0);
      }
   
    if(ev.getSource() == botonLimpiar)
      {

         num.setText("");
         resultado.setText("");
      }
      
      
     if(ev.getSource ()==botonCalcular)
     {
        int w=0;
        try
        {
        w=   Integer.parseInt(num.getText());
        }
        catch (Exception e)
        {
           w=0;
   
        }
        //para el calculo
        
     int[] a = new int[0]; 
           for (int i = 1 ; i <=w +1 ; i++)
                 { 
                    
                  int[] x = new int;
                 for (int j = 0; j < i; j++)
                     {
                     if(j==0 || j== (i-1) )
                         {    
                    x[j]=1;
                          }
                        else {
                           
                            x[j]=a[j]+a[j-1];
                        
                            }
            resultado.append( " "+x[j]+" ");
                              }
                            a = x;
                                 
                resultado.append("\n");
                
                
                
              }         
    }
      
   }//fin de action event   
   
public static void main(String args[])
{
new TrianguloPascal();   // Se crea un objeto anonimo (Sin referencia)
}
}
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines