newinsets用法java_JavaFX 类 Insets用法及代码示例

Java程序创建三个inset对象并显示其内容,并检查它们是否相等:此程序将创建三个名为insets_1,insets_2和insets_3的Inset。调用构造函数时,将插入作为参数传递。我们将使用getTop(),getBottom(),getLeft(),getRight()函数获得插图对象的四个侧面并显示它们。我们还将使用equals函数检查inset是否彼此相等。

// Java program to create three objects of insets

// and display its contents and check whether

// they are equal to each other or not

import javafx.geometry.Insets;

public class Insets_2 {

// Main Method

public static void main(String args[])

{

// create three insets objects

Insets insets_1 = new Insets(120.0f, 150.0f,

40.0f, 60.0f);

Insets insets_2 = new Insets(120.0f, 150.0f,

40.0f, 60.0f);

Insets insets_3 = new Insets(200.0f, 120.0f,

60.0f, 40.0f);

// display the 3 insets

display(insets_1);

display(insets_2);

display(insets_3);

// check whether any insets is equal to other or not

System.out.println("Insets 1 equals Insets 2 = "

+ insets_1.equals(insets_2));

System.out.println("Insets 2 equals Insets 3 = "

+ insets_2.equals(insets_3));

System.out.println("Insets 3 equals Insets 1 = "

+ insets_3.equals(insets_1));

}

// display Method

public static void display(Insets insets)

{

double left, right, bottom, top;

// get the insets

left = insets.getLeft();

right = insets.getRight();

bottom = insets.getBottom();

top = insets.getTop();

// display the insets

System.out.println("Insets of the object");

System.out.println("Left= " + left + ", Right= "

+ right + ", Bottom= " + bottom

+ ", Top = " + top);

}

}

输出:

Insets of the object

Left= 60.0, Right= 150.0, Bottom= 40.0, Top = 120.0

Insets of the object

Left= 60.0, Right= 150.0, Bottom= 40.0, Top = 120.0

Insets of the object

Left= 40.0, Right= 120.0, Bottom= 60.0, Top = 200.0

Insets 1 equals Insets 2 = true

Insets 2 equals Insets 3 = false

Insets 3 equals Insets 1 = false

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值