[[oktatas:programozás:java:java_fx|< Java FX]]
====== JavaFX - Operációs rendszer ======
* **Szerző:** Sallai András
* Copyright (c) 2024, Sallai András
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC BY-SA 4.0]]
* Web: https://szit.hu
===== Kilépés =====
import javafx.application.Platform;
//...
Button exitButton = new Button("Kilépés");
exitButton.setOnAction(event -> {
Platform.exit();
});
Button exitButton = new Button("Kilépés");
exitButton.setOnAction(event -> {
System.exit(0);
});
===== Vágólap =====
==== Másolás ====
package com.example;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
public class MainController {
@FXML
private TextArea editorArea;
@FXML
void onClickCopyButton(ActionEvent event) {
startCopy();
}
private void startCopy() {
String editorText = editorArea.getSelectedText();
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(editorText);
clipboard.setContent(content);
}
}
==== Beillesztés ====
@FXML
void onClickPasteButton(ActionEvent event) {
startPaste();
}
private void startPaste() {
Clipboard clipboard = Clipboard.getSystemClipboard();
String content = clipboard.getString();
int cursorPosition = editorArea.getCaretPosition();
editorArea.insertText(cursorPosition,content);
}
==== Kivágás ====
@FXML
void onClickCutButton(ActionEvent event) {
startCut();
}
private void startCut() {
String editorText = editorArea.getSelectedText();
editorArea.deleteText(editorArea.getSelection());
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(editorText);
clipboard.setContent(content);
}