欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

有没有大神帮忙解释一下这段

程序员文章站 2024-02-28 19:55:46
...

/** * 界面逻辑控制器, */@SuppressWarnings(“unused”)
public class FXMLDocumentController implements Initializable {
private Stage stage;
private File fileOpened;

@FXML
private TextArea textArea;

@Override
public void initialize(URL url, ResourceBundle rb) { }

void setStage(Stage stage) {
this.stage = stage;
openFile(null);
}

 private void openFile(File file) {     
    fileOpened = file;       
     if (fileOpened == null) {           
      stage.setTitle("记事本");      
        } else {                         stage.setTitle(fileOpened.getAbsolutePath());      
          }   
           }     private void readFile(File file) {      
             if (file == null) {           
              textArea.setText("");            
              return;       
               }       
                try {            
                textArea.setText(new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))));        } catch (IOException e) {            
                Alert alert = new Alert(Alert.AlertType.ERROR);            alert.setContentText("file open error: " + e.getMessage());            alert.show();        
                }   
                 }    

private void saveFileAs(File file) { try { Files.write(Paths.get(file.getAbsolutePath()), textArea.getText().getBytes());
} catch (IOException e) {
Alert alert = new Alert(Alert.AlertType.ERROR); alert.setContentText(“file write error: " + e.getMessage());
alert.show();
}
openFile(file); }
/** * 功能未实现时调用
* @param event
* */ @FXML
* private void onNotImplementedItemClick(ActionEvent event) { Alert alert = new Alert(Alert.AlertType.ERROR); String text = ((MenuItem) event.getTarget()).getText(); alert.setContentText(text + " not implemented”); alert.show();
}

相关标签: 笔记