Java basic self-study notes-Chapter 14: JavaFX basics

Chapter 14: JavaFx Basics

Course: AWT——>Swing——>JavaFx
JavaFx can run seamlessly in the desktop or web browser

1. Basic structure

java.application.Application defines the basic program of the
JavaFx program. The launch() method
is not necessary to run an independent JavaFx application. The main method is not necessary.
Structure:
Insert picture description here
The size unit of Java graphics is in pixels.
setStoke: pen color
setFill: fill color
in JavaFx , panel The upper left corner is (0,0) x axis increases from left to right, and increases from top to bottom
Insert picture description here

2. Attribute binding

Property binding: If the value in the source object changes, the value of the target object also changes

getCenterX();//值得获取方法,返回double类型的值
CenterXproperty();//属性的获取方法,返回DoubleProperty类型的对象
bind;//单项绑定
bindBidirectional;//双向绑定

3. General properties and methods of nodes

1. Syntax: styleName:value
multiple styles can be set together, separated by semicolons

circle.setStyle("-fx-stroke:black;-fx-full:red");

The rotate attribute can set an angle in degrees, allowing him to rotate the angle around the center

If the angle is greater than 0: clockwise, otherwise, counterclockwise

contains(double x,double y);//检测(x,y)是否在一个节点的边界之内

Four.Color class

opacity : 0.0:完全透明   1.0:完全不透明
r,g,b:    0.0:最深色    1.0:最浅色

V. Events and event sources

Conditions for becoming a processor:

  • The processor must be an instance of the corresponding event processing interface
Action 必须继承自EventHandle<ActionExent> 且必须实现handle方法
  • The processor must be registered with the source object
ActionEvent->setOnAction()
MouseExent->setOnMouseEvent()

Six. Internal class

1. Usually only when a class is only called by an outer class, it is called
an inner class with a characteristic of an inner class

  • The inner class can reference data and methods in the outer class
  • An inner class can be modified with visible modifiers, the same as the visibility rules applied to members of a class
  • An inner class can be defined as static, which can be accessed according to the name of the outer class, but cannot access the non-static members of the outer class
  • The inner class is usually created in the outer class, but you can also create an instance of the inner class from another class. If the inner class is non-static, you must first create an instance of the outer class
Outerclass.Innerclass innerObject=OuterObject.new Innerclass();
  • If the inner class is static, you must use the following syntax to create an instance of the inner class:
Outerclass.Innerclass innerObject=new Outerclass.Innerclass();

2. Generated bytecode file

public class Test{
    
    
    private int d;
    public void m(){
    
    }
    public class A{
    
    
        d++;
    }
}//生成的字节码文件有两个,分别是Test.class 和 Test$A.class

3. Advantages of internal classes:

  • Reduce the number of source files
  • Avoid class name conflicts

Seven. Anonymous inner class

1. Anonymous inner class syntax

new SuperClass/interface(){
    
    
}

Characteristics of anonymous inner classes:

  • Always inherit the parent class or implement an interface, there can be no explicit extends or implements
  • Must implement abstract methods in parent classes and interfaces
  • An anonymous inner class always uses the no-parameter construction of the parent class to create an instance. If an anonymous inner class implements an interface, the construction method is Object();
  • Anonymous inner classes are compiled into Test.class and Test$n.class

8. Use lambda expressions to simplify event handling

1. Conditions for using lambda expressions:
an interface containing only one abstract method can be used, such an interface is called a functional interface

btEnlarge.setOnAction(
    new EventHandler<AEvent>(){
    
    
        public void handle(Action Event e){
    
    
        }
     }
)
//上面代码可以简化为:
btEnlarge.setOnAction(e->{
    
    System.out.println("");})

Nine. Animation Basics

PathTransition;//按路线运动
FadeTransision;//按透明度运动
TimeLine;//按时间运动

This chapter takes everyone to get a basic understanding of javaFx. I don’t know much about it, so I won’t start talking about it.

Come on! Chapter 15 To Be More...

Guess you like

Origin blog.csdn.net/weixin_42563224/article/details/104543522