2016-10-02 4 views
0

이것은 내 첫 번째 게시물입니다.JavaFX 텍스트 영역 : 각 줄의 끝에 "-"을 추가하십시오.

NetBeans IDE를 사용하고 있으며 JavaFX 프로젝트에 Scene Builder를 사용하고 있습니다. "-" 가 나는 또한 내가로 끝나는 텍스트 영역에서 라인을 만들려고 노력하고있는 액션

void addAction(ActionEvent event) { 
} 

와 버튼이 변수 "정의" 와 텍스트 영역이있다.

는 시각화 : 입력 :

happy 
sad 
good 
bad 

출력 :

happy - 
sad - 
good - 
bad - 

I 루프이있다 :

for (int i = 0 ; definitions.getText().split("\\n"); i++){ 
     String previous = definitions.getText(); 
     definitions.setText(previous + " - "); 
     } 

되지만 출력은 :

happy 
sad 
good 
bad - - - - 

누군가 나를 도와 줄 수 있습니까? 감사합니다. MineRockers 여기

너희들은 그것을 경우 전체 코드를 필요로한다 :

package vocabulary.javafx; 

import java.net.URL; 
import java.awt.Desktop; 
import java.io.BufferedWriter; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.util.ResourceBundle; 
import javafx.event.ActionEvent; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.control.*; 

public class FXMLDocumentController implements Initializable { 

    //Declaration... 
    private boolean Email; 
    private boolean Save; 
    private String Word; 

    @FXML 
    private Button add; 

    @FXML 
    private TextArea sentences; 

    @FXML 
    private Button searchS; 

    @FXML 
    private TextField helpD; 

    @FXML 
    private Button finish; 

    @FXML 
    private Label label; 

    @FXML 
    private TextField helpS; 

    @FXML 
    private TextArea definitions; 

    @FXML 
    private Button searchD; 

    @FXML 
    void addAction(ActionEvent event) { 
     String previous = definitions.getText(); 
     String[] linecountS = definitions.getText().split("\n"); 
     for() 
     int lineCount = Integer.parseInt(linecountS); 
     //for (int i = 0 ; definitions.getText().split("\\n"); i++){ 
     // String previous = definitions.getText(); 
     // definitions.setText(previous + "-"); 
     //} 
    } 

    @FXML 
    void helpDAction(ActionEvent event) { 
     //Enter Key Pressed 
     Word = helpD.getText(); 
     if (Desktop.isDesktopSupported()) { 
      try { 
       Desktop.getDesktop().browse(new URI("http://www.dictionary.com/browse/" + Word + "?s=t")); 
      } catch (URISyntaxException | IOException ex) { 
      } 
     } 
    } 

    @FXML 
    void helpSAction(ActionEvent event) { 
     //Enter Key Pressed 
     Word = helpS.getText(); 
     if (Desktop.isDesktopSupported()) { 
      try { 
       Desktop.getDesktop().browse(new URI("http://sentence.yourdictionary.com/" + Word)); 
      } catch (URISyntaxException | IOException ex) { 
      } 
     } 
    } 

    @FXML 
    void searchDAction(ActionEvent event) { 
     //Button Clicked 
     Word = helpD.getText(); 
     if (Desktop.isDesktopSupported()) { 
      try { 
       Desktop.getDesktop().browse(new URI("http://www.dictionary.com/browse/" + Word + "?s=t")); 
      } catch (URISyntaxException | IOException ex) { 
      } 
     } 
    } 

    @FXML 
    void searchSAction(ActionEvent event) { 
     //Button Clicked 
     Word = helpS.getText(); 
     if (Desktop.isDesktopSupported()) { 
      try { 
       Desktop.getDesktop().browse(new URI("http://sentence.yourdictionary.com/" + Word)); 
      } catch (URISyntaxException | IOException ex) { 
      } 
     } 
    } 

    @FXML 
    void finishAction(ActionEvent event) { 
     String Content1 = definitions.getText(); 
     String Content2 = sentences.getText(); 
     String Finalized = "Auto-generated message by Vocabulary 2.0 by MineRocker\n\nDefinitions:\n" + Content1 + " \n\n\nSentences:\n" + Content2; 

     if (Desktop.isDesktopSupported()) { 
      try { 
       Desktop.getDesktop().browse(new URI("gmail.com")); 
      } catch (URISyntaxException | IOException ex) { 
      } 

      FileWriter fileWriter; 
      try { 
       fileWriter = new FileWriter("AFile.txt"); 
       try (BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) { 
        bufferedWriter.write(Finalized); 
       } 

      } catch (IOException ex) { 
      } 
     } 
    } 

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

    } 

} 
+0

얘들 아, 어떤 제안이, 돈 좋다 ' 댓글을 달거나 답변을 주저하지 마십시오! –

답변

0

이 코드 추가를 "-"어떤 줄 뒤에 :

String str = definitions.getText().replaceAll("\n", " -\n"); 
str = str + " -";// add "-" to last line 
definitions.setText(str); 
+0

오 이런, 작동! 정말 고맙습니다. –

관련 문제