This example adds a handle to a button on the basis of an instance (10), which can be scaled using a button on a circle in an instance (10).
The code for this example is as follows:
import javafx.application.application;import javafx.event.actionevent;import javafx.event.eventhandler;import javafx.geometry.pos;import javafx.scene.scene;import javafx.scene.control.button;import javafx.scene.layout.stackpane;import javafx.scene.layout.hbox; import javafx.scene.layout.borderpane;import javafx.scene.paint.color;import javafx.scene.shape.circle;import javafx.stage.stage; public class controlcircle extends application { private circlepane circlepane = new Circlepane (); @Override // Override the start Method in the application class public void start (stage primarystage) { Hbox hbox = new hbox (); &nBsp; hbox.setspacing (Ten); hbox.setalignment (Pos.center); button btenlarge = new button ("enlarge"); button btshrink = new button ("Shrink"); hbox.getchildren (). Add (Btenlarge); hbox.getchildren (). Add (Btshrink); btenlarge.setonaction (New enlargehandler ()); btshrink.setonaction (New shrinkhandler ()); BorderPane Borderpane = new borDerpane (); borderpane.setcenter (CirclePane); borderpane.setbottom (HBox); borderpane.setalignment (HBox, Pos.CENTER); scene scene = new scene ( borderpane, 200, 150); Primarystage.settitle ("Controlcircle"); Primarystage.setscene (Scene); Primarystage.show (); } class EnlargeHandler implements EventHandler<ActionEvent> { &nbSp;public void handle (actionevent e) { circlepane.enlarge (); } } class ShrinkHandler implements EventHandler<ActionEvent> { public void handle ( Actionevent e) { circlepane.shrink (); } } } class CirclePane extends StackPane { private circLe circle = new circle (; ) public circlepane () { getchildren (). Add (Circle) ; circle.setstroke (Color.BLACK); circle.setfill (Color.WHITE); } public void enlarge () { circle.setradius (Circle.getradius () +2); } public void shrink () { &nBsp; circle.setradius (Circle.getradius () >2? circle.getradius () - 2 : Circle.getradius ()); } }
This article is from the "Fengbin Technology blog" blog, make sure to keep this source http://fengbin8606.blog.51cto.com/8840305/1575044
Fengbin: JavaFX Instance (11) "Controlcircle"