domingo, 18 de fevereiro de 2018

Javafx - calculando fatorial

Do código de uma calculadora em javafx criada
por mim mesmo, apresento esta funcionalidade
extraída, já que o código completo não foi publicado.
"Veja o vídeo no blog com o programa em execução".
Nesta versão estamos calculando o fatorial de um

 número e imprimindo os resultados num
TextField do javafx.
Alguns comentários foram colocados onde achei
necessário, aproveite este código que é uma oferta
gratuita do meu blog de java, e é indicado apenas
para estudos, para qualquer outro uso, os créditos
do autor que sou eu mesmo devem ser respeitados.    

 Veja abaixo uma imagem do programa em execução:




 Veja abaixo um vídeo com o programa em execução:


Veja abaixo o código do programa: 

import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

////////////////////////////////////////////////////////////////////////////////
public class PROJETO extends Application {
     static StringBuilder str1 = new StringBuilder ( );
     static Boolean x = false;
     static String key = "";
     static String str_2 = "";
     static String str_3 = "";
     static int a = 0, b = 0;
     static double i, m = 0, fact;
     static char vet; 
     private static Button btn_1           = new Button ( "1" );
     private static Button btn_2           = new Button ( "2" );
     private static Button btn_3           = new Button ( "3" );
     private static Button btn_4           = new Button ( "4" );
     private static Button btn_5           = new Button ( "5" );
     private static Button btn_6           = new Button ( "6" );
     private static Button btn_7           = new Button ( "7" );
     private static Button btn_8           = new Button ( "8" );
     private static Button btn_9           = new Button ( "9" );
     private static Button btn_0           = new Button ( "0" );
     private static Button btn_ponto       = new Button ( "." );
     private static Button btn_del         = new Button   (  );
     private static Button btn_Rquadr      = new Button ( "Fatorial" );
     static Canvas canvas = new Canvas ( 340, 280 );
     static GraphicsContext ctx = canvas.getGraphicsContext2D ( );
     static Group root = new Group ( );
     static Scene scene = new Scene ( root, 340, 280, Color.BLACK );
     static TextField name = new TextField ( );
     static GridPane grid = new GridPane ( );
     // /////////////////////////////////////////////////////////////////////////
     static Text t_0 = new Text ( );
     static Text t_1 = new Text ( );
     static Text t_2 = new Text ( );
     // /////////////////////////////////////////////////////////////////////////
     public static void Numeros ( ) {
         t_0.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 20 ) );
         t_1.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 25 ) );
         t_2.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 15 ) );
         /////////////////////////
         t_2.setX ( 285 );//coluna
         t_2.setY ( 205 );//linha
         t_2.setText ( "←" );
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node Zero ( ) {
         t_0.setVisible ( true );
         t_0.setFill ( Color.BLACK );
         t_0.setX ( 283 );
         t_0.setY ( 108 );
         t_0.setText ( "0" );
         Reset ( );
         return t_0;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static void Reset ( ) {
         if ( vet == '+' ){
              str1 = new StringBuilder ( );
              vet = ' ';
              a = 0;
              i = 0;
              str_3 = ""; 
              str_2 = "";
              x = true;
              name.clear ( );
         }
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_del ( ) {
         btn_del.setStyle ( "-fx-font: 15 arial;"
                   + "-fx-background-color: blue;" );
         btn_del.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_del.setStyle ( "-fx-font: 15 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_del.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_del.setStyle ( "-fx-font: 15 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_del.setPrefWidth ( 40 );// Largura do botão
         btn_del.setLayoutX ( 274 );// Posição do botão coluna
         btn_del.setPrefHeight ( 37 );// altura do botão
         btn_del.setLayoutY ( 181 );// //Posição do botão linha
         btn_del.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   str1 = new StringBuilder ( );
                   name.setEditable ( true );
                   key = btn_del.getText ( );
                   name.deletePreviousChar ( );
                   name.appendText ( key );
                   str_3 = name.getText ( ).toString ( );
                   str1.append ( str_3 );
                   b = name.getText ( ).length ( );
                   if ( b == 1 ) {  
                        name.deleteText ( 0, b );
                        Zero ( );
                   }
              }
         } );
         return btn_del;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_9 ( ) {
         btn_9.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_9.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_9.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_9.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_9.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_9.setPrefWidth ( 40 );// Largura do botão
         btn_9.setLayoutX ( 130 );// Posição do botão coluna
         btn_9.setPrefHeight ( 20 );// altura do botão
         btn_9.setLayoutY ( 181 );// //Posição do botão linha
         btn_9.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {  
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "9" );
                   str_3 = "9";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );    
              }
         } );
         return btn_9;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_8 ( ) {
         btn_8.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_8.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_8.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_8.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_8.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_8.setPrefWidth ( 40 );// Largura do botão
         btn_8.setLayoutX ( 82 );// Posição do botão coluna
         btn_8.setPrefHeight ( 20 );// altura do botão
         btn_8.setLayoutY ( 181 );// //Posição do botão linha
         btn_8.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "8" );
                   str_3 = "8";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );
              }
         } );
         return btn_8;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_7 ( ) {
         btn_7.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_7.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_7.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_7.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_7.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_7.setPrefWidth ( 40 );// Largura do botão
         btn_7.setLayoutX ( 32 );// Posição do botão coluna
         btn_7.setPrefHeight ( 20 );// altura do botão
         btn_7.setLayoutY ( 181 );// //Posição do botão linha
         btn_7.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "7" );
                   str_3 = "7";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );
              }
         } );
         return btn_7;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_6 ( ) {
         btn_6.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_6.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_6.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_6.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_6.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_6.setPrefWidth ( 40 );// Largura do botão
         btn_6.setLayoutX ( 274 );// Posição do botão coluna
         btn_6.setPrefHeight ( 20 );// altura do botão
         btn_6.setLayoutY ( 135 );// //Posição do botão linha
         btn_6.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "6" );
                   str_3 = "6";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );
              }
         } );
         return btn_6;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_5 ( ) {
         btn_5.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_5.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_5.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_5.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_5.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_5.setPrefWidth ( 40 );// Largura do botão
         btn_5.setLayoutX ( 226 );// Posição do botão coluna
         btn_5.setPrefHeight ( 20 );// altura do botão
         btn_5.setLayoutY ( 135 );// //Posição do botão linha
         btn_5.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "5" );
                   str_3 = "5";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );
              }
         } );
         return btn_5;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_4 ( ) {
         btn_4.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_4.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_4.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_4.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_4.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_4.setPrefWidth ( 40 );// Largura do botão
         btn_4.setLayoutX ( 178 );// Posição do botão coluna
         btn_4.setPrefHeight ( 20 );// altura do botão
         btn_4.setLayoutY ( 135 );// //Posição do botão linha
         btn_4.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "4" );
                   str_3 = "4";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );
              }
         } );
         return btn_4;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_3 ( ) {
         btn_3.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_3.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_3.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_3.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_3.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_3.setPrefWidth ( 40 );// Largura do botão
         btn_3.setLayoutX ( 130 );// Posição do botão coluna
         btn_3.setPrefHeight ( 20 );// altura do botão
         btn_3.setLayoutY ( 135 );// //Posição do botão linha
         btn_3.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "3" );
                   str_3 = "3";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );
              }
         } );
         return btn_3;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_2 ( ) {
         btn_2.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_2.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_2.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_2.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_2.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_2.setPrefWidth ( 40 );// Largura do botão
         btn_2.setLayoutX ( 82 );// Posição do botão coluna
         btn_2.setPrefHeight ( 20 );// altura do botão
         btn_2.setLayoutY ( 135 );// //Posição do botão linha
         btn_2.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "2" );
                   str_3 = "2";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );
              }
         } );
         return btn_2;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_1 ( ) {
         btn_1.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_1.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_1.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_1.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_1.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_1.setPrefWidth ( 40 );// Largura do botão
         btn_1.setLayoutX ( 32 );// Posição do botão coluna
         btn_1.setPrefHeight ( 20 );// altura do botão
         btn_1.setLayoutY ( 135 );// //Posição do botão linha
         btn_1.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   Reset ( );
                   t_0.setVisible ( false );
                   name.appendText ( "1" );
                   str_3 = "1";
                   a = str_3.length ( );
                   str_3 = str_3.substring ( 0, a );
                   str1.append ( str_3 );
              }
         } );
         return btn_1;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_0 ( ) {
         btn_0.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;" );
         btn_0.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_0.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;" );
              }
         } );
         btn_0.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_0.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;" );
              }
         } );
         btn_0.setPrefWidth ( 40 );// Largura do botão
         btn_0.setLayoutX ( 178 );// Posição do botão coluna
         btn_0.setPrefHeight ( 20 );// altura do botão
         btn_0.setLayoutY ( 181 );// //Posição do botão linha
         btn_0.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   //Reseta a StrinBuilder(), limpa o
                   //textfield, e reseta algumas variáveis
                   Reset ( );
                   //Apaga o zero inicial imprimido no display
                   t_0.setVisible ( false );
                   //Imprime "0" no display
                   name.appendText ( "0" );
                   str_3 = "0";
                   //Pega o tamanho da String
                   a = str_3.length ( );
                   //Apaga para não haver concatenação dos valores repetidos
                   str_3 = str_3.substring ( 0, a );
                   //A StrinBuilder() str1 Recebe a cópia da String
                   str1.append ( str_3 );
              }
         } );
         return btn_0;
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node But_ton_mais ( ) {
         btn_Rquadr.setStyle ( "-fx-font: 20 arial;"
                   + "-fx-background-color: blue;"
                   + "-fx-font-style: italic;");
         btn_Rquadr.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_Rquadr.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: red;"
                            + "-fx-font-style: italic;");
              }
         } );
         btn_Rquadr.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_Rquadr.setStyle ( "-fx-font: 20 arial;"
                            + "-fx-background-color: blue;"
                            + "-fx-font-style: italic;");
              }
         } );
         btn_Rquadr.setPrefWidth ( 282 );// Largura do botão
         btn_Rquadr.setLayoutX ( 32 );// Posição do botão coluna
         btn_Rquadr.setPrefHeight ( 20 );// altura do botão
         btn_Rquadr.setLayoutY ( 226 );// //Posição do botão linha
         btn_Rquadr.setOnAction ( new EventHandler < ActionEvent > ( ) {
              public void handle ( ActionEvent event ) {
                   vet = '+';
                   //Converte StringBuilder em String
                   str_3 = str1.toString ( );
                   str1 = new StringBuilder ( );
                   //Converte a String para double
                   i = Double.parseDouble ( str_3 ); 
                   name.clear ( );
                   str1 = new StringBuilder ( );
                   fact = i;
                   for ( m = ( i - 1 ); m > 1; m-- ) {
                        fact = fact * m;
                   }            
                   str1.append ( fact );      
                   //Elimina os dois últimos caracteres da string
                   //que corresponde a: ( .0 )
                   str_2 = str1.substring ( 0, str1.length ( ) -2 );
                   // Imprime o resultado
                   // opcionalmente no console
                   System.out.println ( str_2 );
                   //Imprime o resultado no display
                   name.appendText ( " " + str_2  );   
                   t_1.setX ( 80 );//Coluna
                   t_1.setY ( 45 );//Linha
                   t_1.setText ( "Por: Samuel Lima" );
                   if ( x == true )                
                        vet = '+';                 
              }
         } );
         return btn_Rquadr;
     }
////////////////////////////////////////////////////////////////////////////
     public static Node But_ton_ponto ( ) {
         btn_ponto.setStyle ( "-fx-font: 20 arial;-fx-background-color: blue;");
         btn_ponto.addEventHandler ( MouseEvent.MOUSE_ENTERED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_ponto.setStyle ( "-fx-font: 20 arial;-fx-background-color: red;");
              }
         } );
         btn_ponto.addEventHandler ( MouseEvent.MOUSE_EXITED,
                   new EventHandler < MouseEvent > ( ) {
              @Override
              public void handle ( MouseEvent e ) {
                   btn_ponto.setStyle ( "-fx-font: 20 arial;-fx-background-color: blue;");
              }
         } );
         do{
              btn_ponto.setPrefWidth ( 40 );// Largura do botão
              btn_ponto.setLayoutX ( 226 );// Posição do botão coluna
              btn_ponto.setPrefHeight ( 20 );// altura do botão
              btn_ponto.setLayoutY ( 181 );// //Posição do botão linha
              //btn_ponto.setDisable ( true );
              btn_ponto.setOnAction ( new EventHandler < ActionEvent > ( ) {
                   public void handle ( ActionEvent event ) {
                        name.appendText ( "." );   
                        str_3 = ".";
                        //Pega o tamanho da String
                        a = str_3.length ( );
                        //Apaga para não haver concatenação dos valores repetidos
                        str_3 = str_3.substring ( 0, a );
                        //A StrinBuilder() str1 Recebe a cópia da String
                        str1.append ( str_3 );
                   }
              } );
              return btn_ponto;
         }while ( true );
     }
////////////////////////////////////////////////////////////////////////////
     public static int Text_Field ( ) {
         //Posicionamento vertical do textfield
         grid.setVgap ( 5 );
         //Posicionamento horizontal do textfield
         grid.setHgap ( 5 );
         //Tamanho máximo
         grid.setMaxSize ( 340, 440 );
         //Posicionamentos exatos do textfield
         name.setPadding ( new Insets ( 69, 20, 5, 35 ) );
         name.setTranslateX ( 31 );
         name.setTranslateY ( 19 );
         name.setAlignment ( Pos.BOTTOM_RIGHT );
         //Alguns efeitos opcionais nos textos do textfield
         name.setStyle ( "-fx-font-family: Consolas;"
                   + "-fx-font-style: italic;" + "-fx-font-size: 20px;"
                   + "-fx-base: #183308;" );
         name.setPrefColumnCount ( 21 );
         //Permite que o textfield fique todo tempo visível
         name.setVisible ( true );
         // Desliga as piscadas do cursor
         name.setEditable ( false );
         return 0;
     }
     // /////////////////////////////////////////////////////////////////////////
     @Override
     public void start ( Stage stage ) throws FileNotFoundException {
         stage.setTitle ( "JAVAFX - CALCULANDO FATORIAL" );
         Text_Field ( );
         Zero ( );
         Numeros ( );
         But_ton_0 ( );
         But_ton_1 ( );
         But_ton_2 ( );
         But_ton_3 ( );
         But_ton_4 ( );
         But_ton_5 ( );
         But_ton_6 ( );
         But_ton_7 ( );
         But_ton_8 ( );
         But_ton_9 ( );
         But_ton_del ( );
         But_ton_mais ( );
         But_ton_ponto ( );
         root.getChildren ( ).addAll ( canvas, grid, name, btn_del, btn_Rquadr,
                   btn_0, btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_ponto,
                   btn_7, btn_8, btn_9, t_0, t_1, t_2 );                 
         stage.setScene ( scene );
         stage.show ( );
     }
     // /////////////////////////////////////////////////////////////////////////
     public static void main ( String [ ] args ) {
         launch ( args );
     }
}

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.