theperfectpunk

FXMLDocumentController

Sep 27th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1.    
  2.  
  3.     /*FXMLDocumentController.java
  4.     /*
  5.      * To change this license header, choose License Headers in Project Properties.
  6.      * To change this template file, choose Tools | Templates
  7.      * and open the template in the editor.
  8.      */
  9.     package chester;
  10.      
  11.     import java.net.URL;
  12.     import java.io.File;
  13.     import java.util.ResourceBundle;
  14.     import javafx.event.ActionEvent;
  15.     import javafx.fxml.FXML;
  16.     import javafx.fxml.Initializable;
  17.     import javafx.stage.FileChooser;
  18.     import java.io.IOException;
  19.     import javafx.scene.layout.BorderPane;
  20.     import java.io.FileReader;
  21.     import java.io.BufferedReader;
  22.     import javafx.scene.control.TextArea;
  23.      
  24.     /**
  25.      *
  26.      * @author mohit
  27.      */
  28.     public class FXMLDocumentController implements Initializable {
  29.        
  30.         @FXML
  31.         private BorderPane rootPane;
  32.         private TextArea textArea;
  33.        
  34.         @FXML
  35.         private void openFile(ActionEvent event) throws InterruptedException {
  36.             FileChooser fc = new FileChooser();
  37.             fc.setTitle("Open File");
  38.             File file = fc.showOpenDialog(rootPane.getScene().getWindow());
  39.             textArea = new TextArea("");
  40.             try
  41.             {
  42.                 System.out.println(file.getAbsolutePath());
  43.                 BufferedReader br = new BufferedReader(new FileReader(file));
  44.                 while((s=br.readLine())!=null)
  45.                 {
  46.                     System.out.println(s);
  47.                     textArea.appendText(s);
  48.                 }
  49.             }
  50.             catch(IOException e)
  51.             {
  52.                 System.err.format("error", e);
  53.             }
  54.         }
  55.         /*private void handleButtonAction(ActionEvent event) {
  56.             System.out.println("You clicked me!");
  57.             label.setText("Hello World!");
  58.         }*/
  59.        
  60.         @Override
  61.         public void initialize(URL url, ResourceBundle rb) {
  62.             // TODO
  63.         }    
  64.        
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment