我已經創建了這個應用程序,用於類似的編碼和解碼。我創建了用戶輸入文本的第一個文本區域。程序獲取文本。到現在爲止還挺好。
現在我需要用另一組字母或數字或兩者替換每個字母。我試着使用:需要幫助創建一個java(fx)程序,用另一組字符串替換字符串
@FXML
String text;
@FXML
TextArea userText;
@FXML
Label codedTextLabel;
@FXML
private void getTextAction(ActionEvent textEvent) {
String codedText;
text = userText.getText();
//The first if
if (text.contains("a") {
codedText = codedTextLabel.getText() + "50"; //50 means a, 60 means b and so on
codedTextLabel.setText(codedText);
} else {
System.out.println("Searching for more text...");
}
//The second if
if (text.contains("b") {
codedText = codedTextLabel.getText() + "50"; //50 means a, 60 means b and so on
codedTextLabel.setText(codedText);
} else {
System.out.println("Searching for more text...");
...等等...
我創建了多個IFS爲同一文本區域,讓每個如果得到執行,即使其他執行。但它會產生錯誤並且不起作用。任何想法如何創建這樣的應用程序來做到這一點?
什麼文字,你有你的標籤嗎?你期望輸出什麼?你會得到什麼? – assylias
@assylias錯誤是,如果我寫了重複字母,如ababab,結果只有5060。我需要它是506050605060. –