java程序 出现的按钮会闪烁 求解 200
while(!isreach){location.x-=1;btnjiantou.setLocation(location);try{Thread.sleep(nandu...
while(!isreach){
location.x-= 1;
btnjiantou.setLocation(location);
try {
Thread.sleep(nandu);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(location.x%100==0&&a<7) {
thread=new Makethread2(i,nandu,btnjiantou,map);
thread.start();
a++;
}
if(location.x==0){
isreach=true;
}
btnjiantou.setVisible(true);
}
btnjiantou.setVisible(false);
这个一个线程的一部分 另一线程类似,
if(location.x==0){
isreach=true;
thread=new Makethread2(i,nandu,btnjiantou,map);
thread.start();
} 展开
location.x-= 1;
btnjiantou.setLocation(location);
try {
Thread.sleep(nandu);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(location.x%100==0&&a<7) {
thread=new Makethread2(i,nandu,btnjiantou,map);
thread.start();
a++;
}
if(location.x==0){
isreach=true;
}
btnjiantou.setVisible(true);
}
btnjiantou.setVisible(false);
这个一个线程的一部分 另一线程类似,
if(location.x==0){
isreach=true;
thread=new Makethread2(i,nandu,btnjiantou,map);
thread.start();
} 展开
展开全部
Java程序:
import java.awt.Color;
import java.awt.FlowLayout;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main extends JFrame implements Runnable {
JButton btn;
public Main() {
super("闪烁的按钮");
this.setSize(300, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
btn = new JButton("我会闪烁");
this.add( btn);
Thread th = new Thread(this);
th.start();
}
public static void main(String[] args) {
new Main();
}
@Override
public void run() {
int r = 127;
int g = 127;
int b = 127;
int i, j, k;
Random rand = new Random();
while(true) {
i = rand.nextInt(255);
j = rand.nextInt(255);
k = rand.nextInt(255);
r = (r + i) % 255 + 1;
g = (g + j) % 255 + 1;
b = (b + k) % 255 + 1;
btn.setBackground(Color.getHSBColor(r, g, b));
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
运行该程序后,可以看到按钮的背景会持续闪烁。
更多追问追答
追问
我想让他不闪烁
它自动在闪
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询