private void Length() { tfD.setText(String.valueOf(Character.lengthCase(tfC.getText().charAt(0)))); } private void is FirstChar() { tfD.setText(String.valueOf(Character.firstCharCase(tfC.getText().charAt(0)))); } private void toUp() { tfD.setText(String.valueOf(Character.toUpperCase(tfC.getText().charAt(0)))); } private void toLow() { tfD.setText(String.valueOf(Character.toLowerCase(tfC.getText().charAt(0)))); } private void LastChar() { tfD.setText(String.valueOf(Character.lastCharCase(tfC.getText().charAt(0)))); } public static void main(String[] args) { launch(args); } }
时间: 2024-03-12 16:44:27 浏览: 124
在代码中,您需要修改以下两处错误:
1. `Length()` 方法中的 `Character.lengthCase()` 应改为 `Character.toString().length()`,用于获取字符串的长度。
2. `is FirstChar()` 方法中的 `is` 应该改为 `First`,即 `Character.firstCharCase()`,用于获取字符串的第一个字符。
修改后的代码如下:
```java
package application;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class AS3 extends Application {
TextField tfA = new TextField();
TextField tfB = new TextField();
TextField tfC = new TextField();
TextField tfD = new TextField();
Button Length = new Button(" Length ");
Button ToUp = new Button(" To Up");
Button Tolow = new Button(" To low ");
Button FirstChar = new Button(" First Char ");
Button LastChar = new Button(" Last Char ");
@Override
public void start(Stage primaryStage) {
GridPane gridPane = new GridPane();
gridPane.setHgap(5);
gridPane.setVgap(5);
gridPane.add(new Label("Student ID:"), 0, 0);
gridPane.add(tfA, 1, 0);
gridPane.add(new Label("Name:"), 0, 1);
gridPane.add(tfB, 1, 1);
gridPane.add(new Label("A Character"), 0, 3);
gridPane.add(new Label("="), 2, 3);
gridPane.add(new Label("Result"), 5, 3);
gridPane.add(tfC, 1, 4);
gridPane.add(tfD, 5, 4);
gridPane.setAlignment(Pos.CENTER);
tfD.setAlignment(Pos.BOTTOM_RIGHT);
HBox hBox = new HBox(Length, ToUp, Tolow, FirstChar, LastChar);
hBox.setAlignment(Pos.CENTER);
BorderPane borderPane = new BorderPane();
borderPane.setCenter(gridPane);
borderPane.setBottom(hBox);
Length.setOnAction(e -> Length());
ToUp.setOnAction(e -> toUp());
Tolow.setOnAction(e -> toLow());
FirstChar.setOnAction(e -> FirstChar());
LastChar.setOnAction(e -> LastChar());
Scene scene = new Scene(borderPane, 600, 400);
primaryStage.setTitle("Jayce 201044");
primaryStage.setScene(scene);
primaryStage.show();
}
private void Length() {
tfD.setText(String.valueOf(tfC.getText().length()));
}
private void FirstChar() {
tfD.setText(String.valueOf(tfC.getText().charAt(0)));
}
private void toUp() {
tfD.setText(String.valueOf(Character.toUpperCase(tfC.getText().charAt(0))));
}
private void toLow() {
tfD.setText(String.valueOf(Character.toLowerCase(tfC.getText().charAt(0))));
}
private void LastChar() {
tfD.setText(String.valueOf(tfC.getText().charAt(tfC.getText().length() - 1)));
}
public static void main(String[] args) {
launch(args);
}
}
```
阅读全文