Veja uma imagem do programa em execução:
Veja abaixo o código do programa:
Veja abaixo o código do programa:
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.Pane;
import javafx.event.ActionEvent;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.event.EventHandler;
import javafx.scene.paint.Color;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.concurrent.Task;
public class PROJETO extends Application {
static String str_2 = "MUITO OBRIGADO";
static String str_1 = "Por: Samuel Lima";
static String str = new String ( );
static Button btn_1 = new Button ( "Inf" );
static Button btn_2 = new Button ( "Cls" );
static Text t1 = new Text ( );
static Text t2 = new Text ( );
static Text t3 = new Text ( );
static Group g = new Group ( );
static Canvas canvas = new Canvas ( );
static GraphicsContext ctx = canvas.getGraphicsContext2D ( );
static TextArea text = new TextArea ( );
static VBox vbox = new VBox ( );
static GridPane grid = new GridPane ( );
static MenuBar menuBar = new MenuBar ( );
static Pane ro_ot = new Pane ( );
static BorderPane root = new BorderPane ( );
static Scene scene = new Scene ( vbox, 500, 500 );
//
/////////////////////////////////////////////////////////////////////////
public static Node But_ton_1 ( ) {
btn_1.setPrefWidth ( 50 );// Largura do botão
btn_1.setLayoutX ( 29 );// Posição do botão
coluna
btn_1.setPrefHeight ( 20 );// altura do botão
btn_1.setLayoutY ( 40 );// //Posição do botão
linha
btn_1.setOnAction ( new EventHandler < ActionEvent > ( ) {
@Override
public void handle ( ActionEvent event ) {
int b = 0;
b = 1;
Sleep ( 1800, b );
b = 2;
Sleep ( 2800, b );
}
} );
ro_ot.getChildren ( ).add ( btn_1 );
return btn_1;
}
////////////////////////////////////////////////////////////////////////////
private static Node But_ton_2 ( ) {
btn_2 .setPrefWidth ( 50 );// Largura do botão
btn_2.setLayoutX ( 357 );// Posição do botão
coluna
btn_2 .setPrefHeight ( 20 );// altura do botão
btn_2 .setLayoutY ( 40 );// //Posição do botão
linha
btn_2.setOnAction ( new EventHandler < ActionEvent > ( ) {
@Override
public void handle ( ActionEvent event ) {
// Coluna, linha,
comprimento, altura
// Apagando uma linha
ou partes
ctx.clearRect ( 80, 120, 180, 80 );
t2.setVisible( false );
t3.setVisible( false );
btn_1.setVisible ( false );
btn_2.setVisible ( false );
}
} );
ro_ot.getChildren ( ).add ( btn_2 );
return btn_2;
}
//
/////////////////////////////////////////////////////////////////////////
// Chamando uma função depois de um certo
tempo
public static void Tempo_2 ( ) {
t3.setFont ( Font.font ( null, FontWeight.BOLD, 15 ) );
t3.setX ( 110 );
t3.setY ( 130 );
t3.setFill ( Color.BLUE );
t3.setText ( str_2 );
root.getChildren ( ).add ( t3 );
}
public static void Tempo_1 ( ) {
t2.setFont ( Font.font ( null, FontWeight.BOLD, 15 ) );
t2.setX ( 110 );
t2.setY ( 110 );
//g.setCache ( true );
t2.setFill ( Color.RED );
t2.setText ( str_1 );
root.getChildren ( ).add ( t2 );
}
public static int Sleep ( int x, int k ) {
Task < Integer > close = new Task < Integer > ( ) {
@Override
protected Integer call ( ) throws Exception {
Thread.sleep ( x );
return null;
}
};
close.setOnSucceeded ( c -> {
if ( k == 1 )
Tempo_1 ( );
if ( k == 2 )
Tempo_2 ( );
} );
new Thread ( close ).start ( );
return 0;
}
//
/////////////////////////////////////////////////////////////////////////
public static int Menu_Bar ( ) {
EventHandler < ActionEvent > action = changeTabPlacement ( );
Menu menu = new Menu ( "Arq" );
MenuItem top = new MenuItem ( "Exit" );
top.setOnAction ( action );
menu.getItems ( ).add ( top );
MenuItem bottom = new MenuItem ( "Inf" );
bottom.setOnAction ( action );
menu.getItems ( ).add ( bottom );
menuBar.getMenus ( ).add ( menu );
root.setTop ( menuBar );
return 0;
}
//
/////////////////////////////////////////////////////////////////////////
private static EventHandler < ActionEvent > changeTabPlacement ( ) {
return new EventHandler < ActionEvent > ( ) {
public void handle ( ActionEvent event ) {
MenuItem mItem = ( MenuItem ) event.getSource ( );
String side = mItem.getText ( );
if ( "Exit".equalsIgnoreCase ( side ) ) {
System.exit ( 0 );
} else if ( "Inf".equalsIgnoreCase ( side ) ) {
But_ton_1 ( );
But_ton_2 ( );
}
}
};
}
//
/////////////////////////////////////////////////////////////////////////
public static int Text_Area ( ){
t1.setFont ( Font.font ( null, FontWeight.BOLD, 15 ) );
t1.setX ( 80 );
t1.setY ( 50 );
t1.setFill ( Color.RED );
t1.setText ( "MOLDURA -
MENU - TEXTAREA E BOTÕES" );
text = new TextArea ( str );
grid.setVgap ( 4 );
grid.setHgap ( 2 );
root.setPadding ( new Insets ( 1, 1, 1, 1 ) );
//Posiciona a Margem do TextArea
grid.add ( text, 1, 20, 2, 10 );
root.setMinWidth ( 150 );
text.setStyle ( "-fx-font-style:
italic;"
+ "
-fx-font-weight: bolder;"
+ " -fx-font-size: 15px;"
+ "-fx-alignment: center;"
+ "-fx-text-fill:
blue" );
root.getChildren ( ).addAll ( grid, t1 );
return 0;
}
////////////////////////////////////////////////////////////////////////////
@Override
public void start ( Stage stage ) throws Exception {
stage.setTitle ( "MOLDURA -
MENU - TEXTAREA E BOTÕES" );
Menu_Bar ( );
// Dando uns efeitos na moldura
vbox.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;" );
Text_Area ( );
vbox.getChildren ( ).addAll ( canvas, root, ro_ot, grid );
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.