如何在 textArea JavaFx 上打印值?是否可以将 void 更改为字符串?
How can I print the values on textArea JavaFx? Is it possible to change the void to string?
public void printHashTable()
{
for (int i = 0; i < TABLE_SIZE; i++)
{
System.out.print("\nBucket "+ (i + 1) +" : ");
LinkedHashEntry entry = table[i];
while (entry != null)
{
System.out.print("["+entry.data +" ,"+entry.value+"]>");
entry = entry.next;
}
}
}
// class JavaFx
// How can I get the value in JAVAFX
Print_button.setOnAction((ActionEvent e) -> {
textArea.setWrapText(ht.printHashTable());
});
How can I get the value in JAVAFX
How can I print the values on textArea JavaFx? Is it possible to change the void to string?
in this textArea.setWrapText(ht.printHashTable());
使用 StringBuilder
构建字符串,return 它:
public String printHashTable() {
StringBuilder result = new StringBuilder();
for (int i = 0; i < TABLE_SIZE; i++) {
result.append("\nBucket ")
.append(i + 1)
.append(" : ");
LinkedHashEntry entry = table[i];
while (entry != null) {
result.append("[")
.append(entry.data)
.append(" ,")
.append(entry.value)
.append("]>");
entry = entry.next;
}
}
return result.toString();
}
我想你的意思是
printButton.setOnAction(e -> textArea.setText(ht.printHashTable()));
public void printHashTable()
{
for (int i = 0; i < TABLE_SIZE; i++)
{
System.out.print("\nBucket "+ (i + 1) +" : ");
LinkedHashEntry entry = table[i];
while (entry != null)
{
System.out.print("["+entry.data +" ,"+entry.value+"]>");
entry = entry.next;
}
}
}
// class JavaFx
// How can I get the value in JAVAFX
Print_button.setOnAction((ActionEvent e) -> {
textArea.setWrapText(ht.printHashTable());
});
How can I get the value in JAVAFX How can I print the values on textArea JavaFx? Is it possible to change the void to string? in this textArea.setWrapText(ht.printHashTable());
使用 StringBuilder
构建字符串,return 它:
public String printHashTable() {
StringBuilder result = new StringBuilder();
for (int i = 0; i < TABLE_SIZE; i++) {
result.append("\nBucket ")
.append(i + 1)
.append(" : ");
LinkedHashEntry entry = table[i];
while (entry != null) {
result.append("[")
.append(entry.data)
.append(" ,")
.append(entry.value)
.append("]>");
entry = entry.next;
}
}
return result.toString();
}
我想你的意思是
printButton.setOnAction(e -> textArea.setText(ht.printHashTable()));