Código:
package java.lang; import java.awt.EventQueue; public class Factorial { private JFrame frmFactorial; private JTextField textField; public Integer numero; public double factorial; public String cadena; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Factorial window = new Factorial(); window.frmFactorial.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Factorial() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frmFactorial = new JFrame(); frmFactorial.setTitle("Factorial"); frmFactorial.setBounds(100, 100, 450, 300); frmFactorial.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmFactorial.getContentPane().setLayout(null); textField = new JTextField(); textField.setBounds(124, 51, 184, 39); frmFactorial.getContentPane().add(textField); textField.setColumns(10); JButton btnNewButton = new JButton("Calcular"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cadena=textField.getText(); numero=Integer.valueOf(cadena); factorial=calcular_factorial(numero); //System.out.println("Resultado: "+factorial); textField.setText((int)factorial); } }); btnNewButton.setBounds(167, 101, 94, 39); frmFactorial.getContentPane().add(btnNewButton); JLabel lblIntroduceUnNmero = new JLabel("Introduce un n\u00FAmero para calcular su factorial."); lblIntroduceUnNmero.setBounds(87, 11, 254, 23); frmFactorial.getContentPane().add(lblIntroduceUnNmero); } public static double calcular_factorial (Integer numero){ double resul=1; for(int i=numero;i>0;i--){ resul*=i; } return resul; } }