java中borderpane_java - 重绘BorderPane(javaFx) - 堆栈内存溢出

我有一个可以创建尺寸减小的矩形的应用程序,例如经过10秒的时间,但是这里是当我尝试缩小矩形时,出现窗口错误(场景中未显示任何内容)并等待倒计时完成以停止错误检查(然后显示未缩小的矩形)。 我试图在Internet上找到与Swing中的重绘等效的功能,但不是平均水平:/ this.requestLayout()->我在Internet上找到了此功能,但是它不起作用。 这是我的倒计时代码:

public class Compteur {

DemoBorderPane p ;

public DemoBorderPane getPan() {

if(p==null) {

p = new DemoBorderPane();

}

return p;

}

public Compteur() {

}

public void lancerCompteur() throws InterruptedException {

int leTempsEnMillisecondes=1000;

for (int i=5;i>=0;i--) {

try {

Thread.sleep (leTempsEnMillisecondes);

}

catch (InterruptedException e) {

System.out.print("erreur");

}

System.out.println(i);

getPan().diminuerRect(35);

}

}

}

有我的Borderpane代码:

public class DemoBorderPane extends BorderPane {

private Rectangle r;

public Rectangle getRect() {

if(r==null) {

r = new Rectangle();

r.setWidth(350);

r.setHeight(100);

r.setArcWidth(30);

r.setArcHeight(30);

r.setFill( //on remplie notre rectangle avec un dégradé

new LinearGradient(0f, 0f, 0f, 1f, true, CycleMethod.NO_CYCLE,

new Stop[] {

new Stop(0, Color.web("#333333")),

new Stop(1, Color.web("#000000"))

}

)

);

}

return r;

}

public void diminuerRect(int a) {

getRect().setWidth(getRect().getWidth()-a);

int c= (int) (getRect().getWidth()-a);

System.out.println(c);

this.requestLayout();

//this.requestFocus();

}

public DemoBorderPane() {

this.setBottom(getRect());

}

}

有我的主要代码:

public class Main extends Application {

private DemoBorderPane p;

public DemoBorderPane getPan() {

if(p==null) {

p = new DemoBorderPane();

}

return p;

}

@Override

public void start(Stage primaryStage) {

Compteur c = new Compteur();

try {

//Group root = new Group();

Scene scene = new Scene(getPan(),800,600);

//scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

//root.getChildren().add(getPan());

primaryStage.setScene(scene);

primaryStage.show();

} catch(Exception e) {

e.printStackTrace();

}

try {

c.lancerCompteur();

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static void main(String[] args) {

launch(args);

/*Son s = null;

try {

s = new Son();

} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

s.volume(0.1);

s.jouer();

c.lancerCompteur();

s.arreter();*/

}

}

谢谢 ;)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值