Fengbin: JavaFX Instance (11) "Controlcircle"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.