package application;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
public class Main extends Application {
TextField inputR=new TextField();
TextField inputH=new TextField();
TextField inputL=new TextField();
TextField vol=new TextField();
TextField sur=new TextField();
Button calbtn1=new Button("圆锥体积");
Button calbtn2=new Button("圆锥表面积");
Button clearbtn=new Button("清空");
@Override
public void start(Stage primaryStage) {
try {
GridPane root = new GridPane();
root.setPadding(new Insets(20,20,20,20));
root.setHgap(20);
root.setVgap(20);
root.setStyle("-fx-background-color:lightblue");
root.add(new Label("请输入圆锥的底面半径"), 0, 0);
root.add(inputR, 1, 0);
root.add(new Label("请输入圆锥的高"), 0, 1);
root.add(inputH, 1, 1);
root.add(new Label("请输入圆锥的母线长"), 0, 2);
root.add(inputL, 1, 2);
root.add(new Label("圆锥体积为"), 0, 4);
root.add(vol, 1, 4);
root.add(new Label("圆锥的表面积为"), 0, 3);
root.add(sur, 1, 3);
HBox hb=new HBox();
hb.setSpacing(60);
hb.getChildren().addAll(calbtn1,calbtn2,clearbtn);
hb.setAlignment(Pos.CENTER);
root.add(hb, 0, 5,2,1);
Police wang=new Police();
calbtn1.setOnAction(wang);
calbtn2.setOnAction(wang);
clearbtn.setOnAction(wang);
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("求圆锥的体积");
primaryStage.setTitle("求圆锥的表面积");
primaryStage.setResizable(false);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
class Police implements EventHandler<A