Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.34 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.ActionEvent;
  5. import javafx.event.EventHandler;
  6. import javafx.geometry.Insets;
  7. import javafx.geometry.Pos;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.control.Label;
  11. import javafx.scene.control.TextField;
  12. import javafx.scene.layout.GridPane;
  13. import javafx.scene.layout.HBox;
  14. import javafx.scene.layout.Pane;
  15. import javafx.scene.text.Text;
  16. import javafx.stage.Stage;
  17.  
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.Random;
  21.  
  22. /**
  23.  * Created by breetonia on 31.10.2014.
  24.  */
  25.  
  26.  
  27. public class GameApp extends Application {
  28.     GridPane grid;
  29.     GridPane grid2;
  30.     Stage currentStage;
  31.  
  32.     public static void main(String[] args) {
  33.         launch(args);
  34.     }
  35.  
  36.     public void initPane() {
  37.         grid = new GridPane();
  38.         grid.setAlignment(Pos.CENTER);
  39.         grid.setHgap(10);
  40.         grid.setVgap(10);
  41.         grid.setPadding(new Insets(25, 25, 25, 25));
  42.  
  43.         Text scenetitle = new Text("Welcome");
  44.         scenetitle.setId("welcome-text");
  45.         grid.add(scenetitle, 0, 0, 2, 1);
  46.  
  47.         Label userName = new Label("PlayerName:");
  48.         grid.add(userName, 0, 1);
  49.  
  50.         TextField userTextField = new TextField();
  51.         grid.add(userTextField, 1, 1);
  52.  
  53.         Button btn = new Button("Sign in");
  54.         HBox hbBtn = new HBox(10);
  55.         hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
  56.         hbBtn.getChildren().add(btn);
  57.         grid.add(hbBtn, 1, 4);
  58.  
  59.         final Text actiontarget = new Text();
  60.         actiontarget.setId("actiontarget");
  61.         grid.add(actiontarget, 1, 6);
  62.  
  63.         btn.setOnAction(new EventHandler<ActionEvent>() {
  64.  
  65.             @Override
  66.             public void handle(ActionEvent e) {
  67.                 actiontarget.setText("Sign in button pressed");
  68.                 hide(grid);
  69.                 initPane2();
  70.                 changeScene();
  71.                 try {
  72.                     Thread.sleep(2000);
  73.                 } catch (InterruptedException e1) {
  74.                     e1.printStackTrace();
  75.                 }
  76.             }
  77.         });
  78.  
  79.     }
  80.  
  81.     public void show(GridPane pane) {
  82.         pane.setVisible(true);
  83.     }
  84.  
  85.     public void hide(GridPane pane) {
  86.         pane.setVisible(false);
  87.     }
  88.  
  89.     public void initPane2() {
  90.         grid2 = new GridPane();
  91.         grid2.setPrefSize(500, 380);
  92.         grid2.setPadding(new Insets(0, 0, 0, 0));  // внутренний отступ
  93.         grid2.setHgap(8);
  94.         grid2.setVgap(3);
  95.         grid2.setAlignment(Pos.BOTTOM_CENTER);
  96.         Button[][] btn = new Button[5][6];
  97.         Label label = new Label("GUN");
  98.         label.setId("score");
  99. //        label.setPadding(new Insets(0, 0, 0,));
  100.  
  101.         for (int i = 0; i < 5; i++) {
  102.             for (int j = 0; j < 6; j++) {
  103.                 if (j == 0 && (i >= 0 && i < 5)) {
  104.                     btn[i][j] = new Button("");
  105.                     btn[i][j].setPrefSize(120, 65);
  106.                     btn[i][j].setStyle("-fx-font-size: 25px; -fx-font-weight: bold");
  107.                     btn[i][j].setVisible(false);
  108.                     grid2.add(btn[i][j], i, j);
  109.                     continue;
  110.                 }
  111.                 btn[i][j] = new Button("" + getCellValue());
  112.                 btn[i][j].setPrefSize(120, 65);
  113.                 btn[i][j].setStyle("-fx-border-width: 2");
  114.                 btn[i][j].setStyle("-fx-border-radius: 10");
  115.                 btn[i][j].setStyle("-fx-base: #87CEFA; -fx-font-size: 30px;" +
  116.                         "-fx-font-weight: bold");
  117.                 grid2.add(btn[i][j], i, j);
  118.             }
  119.         }
  120.  
  121.         btn[0][0].setVisible(true);
  122.         btn[1][0].setVisible(true);
  123.         btn[0][0].setPadding(new Insets(0, 0, 0, 0));
  124.         btn[0][0].setPrefSize(120, 65);
  125.         btn[0][0].setText("Score: ");
  126.  
  127.         btn[4][0].setVisible(true);
  128.         btn[4][0].setPrefSize(200, 65);
  129.         btn[4][0].setText("Vladislav");
  130.  
  131.     }
  132.  
  133.     public void changeScene() {
  134.         Scene scene2 = new Scene(grid2, 600, 430); // width, height
  135.         this.currentStage.setScene(scene2);
  136.         scene2.getStylesheets().add(GameApp.class.getResource("Game.css").toExternalForm());
  137.         this.currentStage.setResizable(false);
  138.         this.currentStage.show();
  139.     }
  140.  
  141.     public void changeScene(Scene scene, Pane pane) {
  142.         scene = new Scene(pane, 600, 430); // width, height
  143.         this.currentStage.setScene(scene);
  144.         this.currentStage.setResizable(false);
  145.         this.currentStage.show();
  146.     }
  147.  
  148.     public static int getCellValue() {
  149.         List<Integer> cellNumbers = new ArrayList<Integer>();
  150.         cellNumbers.add(200);
  151.         cellNumbers.add(400);
  152.         cellNumbers.add(600);
  153.         cellNumbers.add(800);
  154.         cellNumbers.add(1000);
  155.         int cellIndex = new Random().nextInt(cellNumbers.size() - 1);
  156.         return cellNumbers.get(cellIndex);
  157.     }
  158.  
  159.     @Override
  160.     public void start(Stage primaryStage) throws InterruptedException {
  161.         primaryStage.setTitle("GUESS THE VERB V 1.0");
  162.         this.currentStage = primaryStage;
  163.         initPane();
  164.         Scene scene = new Scene(grid, 300, 250);
  165.         primaryStage.setScene(scene);
  166.         scene.getStylesheets().add(GameApp.class.getResource("LoginForm.css").toExternalForm());
  167.         primaryStage.show();
  168.     }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement