java1119突击

获取窗口坐标

//窗口大小设置
        stage0.xProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number number, Number t1) {
                System.out.println("窗口x坐标"+t1 );
            }//number为老坐标 t1为新坐标
        });

 多窗口技术

        Stage stage0=new Stage();
        stage0.setTitle("今日窗口");
        stage0.show();
        Stage stage1=new Stage();
        stage1.setTitle("dierge");
        stage1.show();

package com.example.test1122;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication1 extends Application {
    @Override
    public void start(Stage stage)  {
        stage.setTitle("今日摆烂");
        stage.getIcons().add(new Image("1.png"));
        stage.setHeight(500);
        stage.setWidth(1000);
        stage.setMaxWidth(1300);
        stage.setMaxHeight(1300);
        Line line=new Line();
        line.setStartY(10.0f);
        line.setStartX(10.0f);
        line.setEndX(150.0f);
        line.setEndY(150.0f);
        line.setStroke(Color.RED);
        line.setStrokeWidth(10);
        Circle circle=new Circle(40,40,30);
        circle.setStroke(Color.rgb(111,244,44));
        circle.setFill(Color.BLUE);
        int x=100;
        int y=100;
        Text text=new Text(x,y,"雪豹我们上!!!1");
        text.setFont(Font.font("楷体",32));
        text.setFill(Color.rgb(20,202,02));
        text.setRotate(10);//字体旋转
        text.setCache(true);
        text.setX(100);
        text.setY(100);
        
        ///
        Group group =new Group();
        group.getChildren().add(line);
        group.getChildren().add(circle);
        group.getChildren().add(text);
        Scene scene=new Scene(group,300,250);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

 字体,图形

换行

text.setWrappingWidth(200);

要用到fxml文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.fx1123.HelloController">
   <children>
      <TextArea id="text11" layoutX="35.0" layoutY="30.0" prefHeight="200.0" prefWidth="543.0" text="如果我们在应用程序中使用流窗格,则所有节点都包含在流中。 水平流动窗格将窗格的元素包裹在其高度,而垂直流动窗格将元素包裹在其宽度处。&#10;&#10;名为FlowPane的类javafx.scene.layout表示Flow Pane。 该类包含7个属性,其中包括 -&#10;&#10;alignment - 此属性表示“流”窗格内容的对齐方式。 您可以使用setter方法setAllignment()设置此属性。&#10;&#10;columnHalignment - 此属性表示垂直流窗格中节点的水平对齐方式。&#10;&#10;rowValignment - 此属性表示水平流窗格中节点的垂直对齐方式。&#10;&#10;Hgap - 此属性是double类型,它表示流窗格的行/列之间的水平间距。&#10;&#10;Orientation - 此属性表示流窗格的方向。&#10;&#10;Vgap - 此属性为double类型,它表示流窗格的行/列之间的垂直间距。" />
      <Label id="label1" fx:id="label11" layoutX="276.0" layoutY="319.0" text="Label" />
      <Button id="button111" fx:id="button11" layoutX="257.0" layoutY="231.0" mnemonicParsing="false" text="welcome" />
   </children>
</AnchorPane>

controller控件

package com.example.fx1123;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

import java.net.URL;
import java.time.LocalTime;
import java.util.ResourceBundle;

public class HelloController implements Initializable {
    @FXML
    public Button button11;
    @FXML
    public Label label11;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        button11.setOnAction(e->{
           label11.setText( LocalTime.now().toString());
            System.out.println("anxia");
        });
    }
}

application

package com.example.fx1123;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 800, 500);
        stage.getIcons().add(new Image("xuexi.jpg"));
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

 

 

很重要 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值