package sample;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import java.beans.EventHandler;
public class Main extends Application {
TextField t1 = new TextField();
TextField t2 = new TextField();
TextField t3 = new TextField();
// Button btOK = new Button();
@Override
public void start(Stage primaryStage) throws Exception{
GridPane pane = new GridPane();
pane.setAlignment(Pos.CENTER);
pane.setHgap(5);
pane.setVgap(5);
t1.setAlignment(Pos.BASELINE_RIGHT);
t2.setAlignment(Pos.BASELINE_RIGHT);
t3.setAlignment(Pos.BASELINE_RIGHT);
// t2.setEditable(false);
// t3.setEditable(false);
pane.add(new Label("Decimal"),0,0);
pane.add(t1,1,0);
pane.add(new Label("Hex"),0,1);
pane.add(t2,1,1);
pane.add(new Label("Binary"),0,2);
pane.add(t3,1,2);
t1.setOnAction(e->{
// String strT1=t1.getText();
int a = Integer.parseInt(t1.getText());
// Integer.toBinaryString(a);
// Integer.toHexString(a);
t2.setText(Integer.toHexString(a)+"");
t3.setText(Integer.toBinaryString(a)+"");
});
t2.setOnAction(e->{
String str = t2.getText();
int a = Integer.parseInt(str,16);
t1.setText(a+"");
t3.setText(Integer.toBinaryString(a)+"");
});
t3.setOnAction(e->{
String str = t3.getText();
int a = Integer.parseInt(str,2);
t1.setText(a+"");
t2.setText(Integer.toHexString(a)+"");
});
primaryStage.setTitle("Exercise16_05");
primaryStage.setScene(new Scene(pane, 300, 150));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
javafx进制转换器
最新推荐文章于 2022-07-25 08:08:25 发布