Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.71 KB | None | 0 0
  1.     private void initGameScreen() {
  2.         PropertiesManager props = PropertiesManager.getPropertiesManager();
  3.  
  4.         // THE GUESS HISTORY GOES IN THE CENTER, WHICH WE'LL DISPLAY
  5.         // USING HTML IN A JEditorPane
  6.         gamePane = new JEditorPane();
  7.         // gamePane.addKeyListener(cheatKeyHandler);
  8.         gamePane.setEditable(false);
  9.         gamePane.setContentType("text/html");
  10.                 //gamePane.setSize( new Dimension( 300, 300) );
  11.                 //gamePane.setPreferredSize( new Dimension( 300, 300 ) );
  12.                
  13.                 JScrollPane jScrollPane = new JScrollPane(gamePane);
  14.                 jScrollPane.setMaximumSize(new Dimension(500,425));
  15.                 jScrollPane.setMinimumSize(new Dimension(500,425));
  16.  
  17.         // LET'S LOAD THE INITIAL HTML INTO THE STATS EDITOR PAGE
  18.         this.loadPage(gamePane, HangManPropertyType.GAME_FILE_NAME);
  19.         HTMLDocument gameDoc = (HTMLDocument) gamePane.getDocument();
  20.         docManager.setGameDoc(gameDoc);
  21.        
  22.         //embed swing into javafx
  23.         final SwingNode swingNode = new SwingNode();
  24.         swingNode.setContent(jScrollPane);
  25.         //ScrollPane guessesScrollPane = new ScrollPane();
  26.         //guessesScrollPane.setContent(swingNode);
  27.                 //guessesScrollPane.setPannable(true);
  28.         //guessesScrollPane.setPrefSize(400, 400);
  29.                 //guessesScrollPane.autosize();
  30.  
  31.         // LOAD THE HangMan PICTURE AT ZERO STAGE
  32.         String HangMan = props
  33.                 .getProperty(HangManPropertyType.HANGMAN0_IMG_NAME);
  34.         Image HangManImg = loadImage(HangMan);
  35.         ImageView image = new ImageView(HangManImg);
  36.         HangManLabel = new Label();
  37.         HangManLabel.setGraphic(image);
  38.         hmPane = new BorderPane();
  39.         hmPane.setCenter(HangManLabel);
  40.         //hmPanel.validate();
  41.  
  42.         // THE SOUTH GAME PANEL WILL BE DIVIDED IN TWO
  43.         BorderPane southGamePane = new BorderPane();
  44.         //southGamePanel.addKeyListener(cheatKeyHandler);
  45.         //southGamePanel.setLayout(new BorderLayout());
  46.  
  47.         // WE'LL PUT THE GUESSING CONTROLS IN THE NORTH OF THE SOUTH
  48.         HBox guessingPane = new HBox();
  49.         guessingPane.setStyle("-fx-background-color:lightgray");
  50.         guessingPane.setAlignment(Pos.CENTER);
  51.        
  52.         //guessingPane.addKeyListener(cheatKeyHandler);
  53.        
  54.         // WHEN USE CHEAT,SHOW SECRET WORD
  55.         guessingPane.setOnKeyPressed(new EventHandler<KeyEvent>(){
  56.  
  57.             @Override
  58.             public void handle(KeyEvent ke) {
  59.                 // TODO Auto-generated method stub
  60.                 cheatKeyHandler.keyPressed(ke);
  61.                                
  62.             }
  63.            
  64.            
  65.         });
  66.  
  67.         // THE NEW GAME BUTTON IS LAST CONTROL FOR THE NORTH OF THE SOUTH
  68.         newGameButton = new Button();
  69.        
  70.         String imageName = props.getProperty(HangManPropertyType.NEW_GAME_IMG_NAME);
  71.         Image newGameButtonImage = loadImage(imageName);
  72.         ImageView newGameButtonImageView = new ImageView(newGameButtonImage);
  73.  
  74.         newGameButton.setGraphic(newGameButtonImageView);
  75.         setTooltip(newGameButton, HangManPropertyType.NEW_GAME_TOOLTIP);
  76.        
  77.         newGameButton.setOnAction(new EventHandler<ActionEvent>(){
  78.  
  79.             @Override
  80.             public void handle(ActionEvent event) {
  81.                 // TODO Auto-generated method stub
  82.                 eventHandler.respondToNewGameRequest();
  83.             }
  84.            
  85.         });
  86.        
  87.         guessingPane.getChildren().add(newGameButton);
  88.  
  89.         // WE'LL PUT THE LETTER BUTTONS IN THE SOUTH OF THE SOUTH
  90.         letterButtonsPane = new HBox();
  91.         letterButtonsPane.setStyle("-fx-background-color: grey");
  92.         letterButtonsPane.setPadding(marginlessInsets);
  93.         letterButtonsPane.setSpacing(3.0);
  94.         ArrayList<String> letters = props
  95.                 .getPropertyOptionsList(HangManPropertyType.LETTER_OPTIONS);
  96.  
  97.         // WE'LL STORE THE ALPHABET LETTERS IN A NICE EASY TO ACCESS HASH TABLE
  98.         letterButtons = new HashMap();
  99.         String fontFamily = props
  100.                 .getProperty(HangManPropertyType.LETTERS_FONT_FAMILY);
  101.         int fontSize = Integer.parseInt(props
  102.                 .getProperty(HangManPropertyType.LETTERS_FONT_SIZE));
  103.         //Font lettersFont = new Font(fontFamily, Font.BOLD, fontSize);
  104.         Font lettersFont = new Font(fontSize);
  105.         Font.font(fontFamily, FontWeight.BOLD, fontSize);
  106.        
  107.         for (int i = 0; i < letters.size(); i++) {
  108.             // MAKE A BUTTON FOR EACH CHARACTER
  109.             Character c = letters.get(i).charAt(0);
  110.             Button letterButton = new Button("" + c);
  111.             letterButton.setFont(lettersFont);
  112.             letterButtons.put(c, letterButton);
  113.             letterButton.setPadding(marginlessInsets);
  114.             letterButton.setBorder(null);
  115.             letterButtonsPane.getChildren().add(letterButton);
  116.             final String guess;
  117.             guess = c.toString();
  118.             // LET THE EVENT HANDLER DEAL WITH WHEN SOMEONE PRESSES THIS BUTTON
  119.             // THE RIGHT LETTER IN SECRET WORD WILL SHOW AS GREEN, WRONG WILL
  120.             // SHOW AS RED
  121.             // AND THEY WOULD BE DISABLED IF CHOSEN.
  122.             letterButton.setOnAction(new EventHandler<ActionEvent>(){
  123.  
  124.                 @Override
  125.                 public void handle(ActionEvent event) {
  126.                     // TODO Auto-generated method stub
  127.                     eventHandler.respondToGuessWordRequest(event.getSource(),
  128.                             guess);
  129.                 }
  130.                
  131.             });
  132.         }
  133.                
  134.  
  135.         // RESET ALL THE LETTER BUTTONS
  136.         resetLetterButtonColors();
  137.  
  138.         // NOW LAY EVERYTHING OUT IN THE GAME PANEL
  139.  
  140.         //gamePanel.setLayout(new BorderLayout());
  141.                
  142.         southGamePane.setTop(guessingPane);
  143.         southGamePane.setBottom(letterButtonsPane);
  144.                 letterButtonsPane.setAlignment(Pos.CENTER);
  145.                 letterButtonsPane.setPrefWidth(800);
  146.                 letterButtonsPane.autosize();
  147.         gamePanel.setCenter(swingNode);
  148.         gamePanel.setBottom(southGamePane);
  149.         gamePanel.setRight(hmPane);
  150.                
  151.                 //gamePanel.setPrefSize(500, 500);
  152.                 gamePanel.autosize();
  153.         // NOW MAKE THIS PANEL PART OF THE WORKSPACE, WHICH MEANS WE
  154.         // CAN EASILY SWITCH TO IT AT ANY TIME
  155.  
  156.         //workspace.add(gamePanel, HangManUIState.PLAY_GAME_STATE.toString());
  157.         //workspace.getChildren().add(gamePanel);
  158.         System.out.println("in the initgamePane");
  159.  
  160.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement