segunda-feira, 25 de dezembro de 2017

Javafx - imprimindo ArrayList de strings

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


Veja abaixo o código do programa:


import java.util.ArrayList;
import java.util.Arrays;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.geometry.Insets;

////////////////////////////////////////////////////////////////////////////////
public class PROJETO extends Application {
     static int b = 0, i;
     static String str = " ";
     static String str_2 = " ";
     static String str_4 = " ";
     static String str_5 = " ";
     static Canvas canvas = new Canvas ( 620, 410 );
     static GraphicsContext ctx = canvas.getGraphicsContext2D ( );
     static BorderPane borderPane = new BorderPane ( );
     static Pane ro_ot = new Pane ( );
     static Scene sce_ne = new Scene ( ro_ot, 620, 410 );
     static Text t_0 = new Text ( );
     static Text t_1 = new Text ( );
     static Text t_2 = new Text ( );
     static Text t_3 = new Text ( );
     static ArrayList < String > arr_List = new ArrayList < > ( Arrays.asList (
              "Alemanha"       , //0
              "Argélia"        , //1
              "Argentina"      , //2
              "Austrália"      , //3
              "Bélgica"        , //4
              "Bósnia"         , //5
              "Brasil"         , //6
              "Camarões"       , //7
              "Chile"          , //8
              "Colômbia"       , //9
              "Coreia do Sul"  , //10
              "Costa do Marfim", //11
              "Costa Rica"     , //12
              "Croácia"        , //13
              "Equador"        , //14
              "Espanha"        , //15
              "Estados Unidos" , //16
              "França"         , //17
              "Gana"           , //18
              "Grécia"         , //19
              "Holanda"        , //20
              "Honduras"       , //21
              "Inglaterra"     , //22
              "Irã"            , //23
              "Itália"         , //24
              "Japão"          , //25
              "México"         , //26
              "Nigéria"        , //27
              "Portugal"       , //28
              "Rússia"         , //29
              "Suíça"          , //30
              "Uruguai"          //31
              ) );
     // ////////////////////////////////////////////////////////////////////////
     public static void TextString ( ) {
         t_0.setFont ( Font.font ( "Arial", FontWeight.BOLD, 25 ) );
         t_1.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 25 ) );
         t_2.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 25 ) );
         t_3.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 25 ) );
     }
     // /////////////////////////////////////////////////////////////////////////
     public static Node Arr_List ( ) {
         Group y = new Group ( );
         ctx.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 15 ) );
         ctx.setFill ( Color.BLUE );
         ctx.fillText ( "O programa dividirá estas", 130, 70 );
         ctx.setFill ( Color.RED );
         ctx.fillText ( "32", 310, 70 );
         ctx.setFill ( Color.BLUE );
         ctx.fillText ( "seleções em", 335, 70 );
         ctx.setFill ( Color.RED );
         ctx.fillText ( "8", 430, 70 );
         ctx.setFill ( Color.BLUE );
         ctx.fillText ( "grupos", 450, 70 );
         for ( i = 0; i < arr_List.size ( ); i++ ) {
              if ( i >= 0 && i <= 15 ) {
                   b++;
                   str_2 += b + "\n";
                   str += arr_List.get ( i ) + "\n";
              }
              if ( i >= 16 && i <= 32 ) {
                   b++;
                   str_4 += b + "\n";
                   str_5 += arr_List.get ( i ) + "\n";
              }
         }        
         //Primeira coluna
         t_1.setFill ( Color.RED );    
         t_1.setX ( 170 );// coluna
         t_1.setY ( 100 );// linha
         t_1.setText ( str_2 );
         t_0.setFill ( Color.BLACK );
         t_0.setX ( 190 );// coluna
         t_0.setY ( 100 );// linha
         t_0.setText ( str );
         ///////////////////////////
         //Segunda coluna
         t_2.setFill ( Color.RED );    
         t_2.setX ( 370 );// coluna
         t_2.setY ( 100 );// linha
         t_2.setText ( str_4 );
         t_3.setFill ( Color.BLACK );
         t_3.setX ( 390 );// coluna
         t_3.setY ( 100 );// linha
         t_3.setText ( str_5 );
         return y;
     }

     // ////////////////////////////////////////////////////////////////////////
     public void start ( Stage stage ) {
         stage.setTitle ( "IMPRIMINDO ARRAY LIST EM JAVAFX" );
         // Dando uns efeitos na moldura
         ro_ot.setStyle ( "-fx-padding: 5;" + "-fx-border-style: solid inside;"
                   + "-fx-border-width: 18;" + "-fx-border-insets: 5;"
                   + "-fx-border-radius: 5;" + "-fx-border-color: blue;" );
         // Configurando o local exato do menu
         borderPane.setPadding ( new Insets ( 23, 500, 0, 23 ) );
         ctx.setFill ( Color.RED );
         ctx.fillText ( "IMPRIMINDO ARRAY LIST EM JAVAFX", 210, 50 );
         Arr_List ( );
         ro_ot.getChildren ( ).addAll ( canvas, borderPane, t_0, t_1,
                   t_2, t_3 );
         stage.setScene ( sce_ne );
         stage.show ( );
     }
     // /////////////////////////////////////////////////////////////////////////
     public static void main ( String [ ] args ) {
         Application.launch ( args );
     }
}

//UM OUTRO EXEMPLO ABAIXO


//IMPRIMINDO ARRAYLIST EM JAVAFX

import java.util.ArrayList;
import java.util.Arrays;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.geometry.Insets;

////////////////////////////////////////////////////////////////////////////////
public class PROJETO extends Application {
     static int b = 0, i;
     static String str = " ";
     static String str_2 = " ";
     static String str_4 = " ";
     static String str_5 = " ";
     static Canvas canvas = new Canvas ( 620, 410 );
     static GraphicsContext ctx = canvas.getGraphicsContext2D ( );
     static BorderPane borderPane = new BorderPane ( );
     static Pane ro_ot = new Pane ( );
     static Scene sce_ne = new Scene ( ro_ot, 620, 410 );
     static ArrayList < String > arr_List = new ArrayList < > ( Arrays.asList (
              "Alemanha"       , //0
              "Argélia"        , //1
              "Argentina"      , //2
              "Austrália"      , //3
              "Bélgica"        , //4
              "Bósnia"         , //5
              "Brasil"         , //6
              "Camarões"       , //7
              "Chile"          , //8
              "Colômbia"       , //9
              "Coreia do Sul"  , //10
              "Costa do Marfim", //11
              "Costa Rica"     , //12
              "Croácia"        , //13
              "Equador"        , //14
              "Espanha"        , //15
              "Estados Unidos" , //16
              "França"         , //17
              "Gana"           , //18
              "Grécia"         , //19
              "Holanda"        , //20
              "Honduras"       , //21
              "Inglaterra"     , //22
              "Irã"            , //23
              "Itália"         , //24
              "Japão"          , //25
              "México"         , //26
              "Nigéria"        , //27
              "Portugal"       , //28
              "Rússia"         , //29
              "Suíça"          , //30
              "Uruguai"          //31
              ) );
     // ////////////////////////////////////////////////////////////////////////
     public static Node Arr_List ( ) {
         Group y = new Group ( );
         ctx.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 15 ) );
         ctx.setFill ( Color.BLUE );
         ctx.fillText ( "O programa dividirá estas", 130, 70 );
         ctx.setFill ( Color.RED );
         ctx.fillText ( "32", 310, 70 );
         ctx.setFill ( Color.BLUE );
         ctx.fillText ( "seleções em", 335, 70 );
         ctx.setFill ( Color.RED );
         ctx.fillText ( "8", 430, 70 );
         ctx.setFill ( Color.BLUE );
         ctx.fillText ( "grupos", 450, 70 );
         for ( i = 0; i < arr_List.size ( ); i++ ) {
              if ( i >= 0 && i <= 15 ) {
                   b++;
                   str_2 += b + "\n";
                   str += arr_List.get ( i ) + "\n";
              }
              if ( i >= 16 && i <= 32 ) {
                   b++;
                   str_4 += b + "\n";
                   str_5 += arr_List.get ( i ) + "\n";
              }
         }
         ctx.setFill ( Color.RED );
         ctx.fillText ( str_2, 170, 100 );
         ctx.setFill ( Color.BLACK );
         ctx.fillText ( str, 190, 100 );
         ctx.setFill ( Color.RED );
         ctx.fillText ( str_4, 370, 100 );
         ctx.setFill ( Color.BLACK );
         ctx.fillText ( str_5, 390, 100 );        
         return y;
     }
     // ////////////////////////////////////////////////////////////////////////
     public void start ( Stage stage ) {
         stage.setTitle ( "IMPRIMINDO ARRAY LIST EM JAVAFX" );
         // Dando uns efeitos na moldura
         ro_ot.setStyle ( "-fx-padding: 5;" + "-fx-border-style: solid inside;"
                   + "-fx-border-width: 18;" + "-fx-border-insets: 5;"
                   + "-fx-border-radius: 5;" + "-fx-border-color: blue;" );
         // Configurando o local exato do menu
         borderPane.setPadding ( new Insets ( 23, 500, 0, 23 ) );
         ctx.setFill ( Color.RED );
         ctx.fillText ( "IMPRIMINDO ARRAY LIST EM JAVAFX", 210, 50 );
         Arr_List ( );
         ro_ot.getChildren ( ).addAll ( canvas, borderPane );
         stage.setScene ( sce_ne );
         stage.show ( );
     }
     // /////////////////////////////////////////////////////////////////////////
     public static void main ( String [ ] args ) {
         Application.launch ( args );
     }
}

//OUTRO EXEMPLO ABAIXO



import java.util.ArrayList;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.geometry.Insets;

////////////////////////////////////////////////////////////////////////////////
public class PROJETO extends Application {
     static int i;
     static String str = " ";
     static Canvas canvas = new Canvas ( 620, 350 );
     static GraphicsContext ctx = canvas.getGraphicsContext2D ( );
     static BorderPane borderPane = new BorderPane ( );
     static Pane ro_ot = new Pane ( );
     static Scene sce_ne = new Scene ( ro_ot, 620, 350 );
     static Text t_0 = new Text ( );
     static ArrayList < String > arr_List = new ArrayList < > ( );
     // /////////////////////////////////////////////////////////////////////////
     public static Node Arr_List ( ) {
         Group y = new Group ( );
         ctx.setFont ( Font.font ( "Arial", FontWeight.NORMAL, 15 ) );
         t_0.setFont ( Font.font ( "Arial", FontWeight.BOLD, 15 ) );
         String st = " ";
         int i = 0;
         ctx.setFill ( Color.BLUE );
         ctx.fillText ( "Imprimindo abaixo o contador de inteiros", 190, 80 );
         ctx.setFont ( Font.font ( "Arial", FontWeight.BOLD, 14 ) );
         ctx.setFill ( Color.BLACK );
         do {
              if ( i % 10 == 0 ){
                   st += "\n";
              }
              if ( i >= 0 && i <= 9 )
                   st += ( "0" );
              st += i + "    ";
              i++;
         } while ( i < 100 );
         arr_List.add ( st );
         // /////////////////////////////////////////////////////////////////////
         for ( i = 0; i < arr_List.size ( ); i++ ) {
              str += arr_List.get ( i ) + "\n";
         }       
         t_0.setFill ( Color.BLACK );
         t_0.setX ( 160 );// coluna
         t_0.setY ( 100 );// linha
         t_0.setText ( str );
         return y;
     }
     // /////////////////////////////////////////////////////////////////////////
     public void start ( Stage stage ) {
         stage.setTitle ( "IMPRIMINDO ARRAY LIST EM JAVAFX" );
         // Dando uns efeitos na moldura
         ro_ot.setStyle ( "-fx-padding: 5;" + "-fx-border-style: solid inside;"
                   + "-fx-border-width: 18;" + "-fx-border-insets: 5;"
                   + "-fx-border-radius: 5;" + "-fx-border-color: blue;" );
         // Configurando o local exato do menu
         borderPane.setPadding ( new Insets ( 23, 500, 0, 23 ) );
         ctx.setFill ( Color.RED );
         ctx.fillText ( "IMPRIMINDO ARRAY LIST EM JAVAFX", 210, 50 );
         Arr_List ( );
         ro_ot.getChildren ( ).addAll ( canvas, borderPane, t_0 );
         stage.setScene ( sce_ne );
         stage.show ( );
     }
     // /////////////////////////////////////////////////////////////////////////
     public static void main ( String [ ] args ) {
         Application.launch ( args );
     }
}
 

Nenhum comentário:

Postar um comentário

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