Java语言程序设计第十版第十六章16.4课后操作题答案

16.4

public class Exercise16_4 extends Application{
	public void start(Stage args){
		GridPane pane = new GridPane();
		pane.setPadding(new Insets(11,12,13,14));
		Label label1 = new Label("Mile:");
		Label label2 = new Label("Kilometer:");  
		TextField textfield = new TextField(); 		
		textfield.setAlignment(Pos.BOTTOM_RIGHT);
		TextField textfield2 = new TextField();
		textfield2.setAlignment(Pos.BOTTOM_RIGHT);
		
		pane.add(label1, 0, 0);
		pane.add(label2, 0, 1); 
		
		textfield.setOnAction(new EventHandler() { 
			public void handle(ActionEvent arg0) {
				// TODO Auto-generated method stub
				double mile = Double.parseDouble(textfield.getText());   
				double kilometer = mile * 1.602307322544464; 
				textfield2.setText("" + kilometer);    
			}}); 
		
		textfield2.setOnAction(new EventHandler() { 
			public void handle(ActionEvent arg0) {
				// TODO Auto-generated method stub
				double kilometer = Double.parseDouble(textfield2.getText());   
				double mile = kilometer / 1.602307322544464; 
				textfield.setText("" + mile);    
			}}); 
		
		pane.add(textfield, 1, 0); 
		pane.add(textfield2, 1, 1);
		Scene scene = new Scene(pane, 250, 80);
		args.setTitle("Exercise16_4");
		args.setScene(scene);
		args.show();
	}
	public static void main(String[] args){
		Application.launch(args);
	}

}

你可能感兴趣的:(Java语言程序设计第十版第十六章16.4课后操作题答案)