如何设置更改 jbuttons 颜色之间的延迟

int p = 0;

int z = 0;

while (p < plaintext.length) {


    while (z < 26) {

        buttons[plaintext[p]+z*26].setBackground(Color.GREEN);

        z++;

    }


    z = 0;

    p++;                        

}

我将一列 26 个按钮设置为具有绿色背景,并以 26 x 26 的按钮网格中的变量P作为起点。所以我的问题是如何在每列更改背景颜色之间延迟,以便它首先显示第一列变为绿色并等待几秒钟,然后显示第二列变为绿色并等待几秒钟等等。


尚方宝剑之说
浏览 148回答 1
1回答

SMILET

在用户Guy提供的链接的帮助下,我能够更改我的代码并获得我想要的结果。如果有人想知道,这是代码。private static void visual() {&nbsp; &nbsp; &nbsp; &nbsp; while (z < 26) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buttons[plaintext[p]+z*26].setBackground(Color.GREEN);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z++;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; z = 0;&nbsp; &nbsp; &nbsp; &nbsp; if (p < plaintext.length) p++;}final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();&nbsp; &nbsp; &nbsp; &nbsp; executorService.scheduleAtFixedRate(new Runnable() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public void run() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;visual();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}, 0, 1, TimeUnit.SECONDS);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java