Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:请教高手,背景颜色的不间断随机变化 [Re:flywithmoon]
littledeer1974

Garbage Collector

CJSDN高级会员


发贴: 1517
积分: 122
于 2004-08-27 16:24 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
[code]
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

class question01 extends JFrame {
question01() {
this.getContentPane().add(new MyPanel());

}

public static void main(String args[]) {
question01 f = new question01();
f.setSize(300, 300);
f.show();
}

}

class MyPanel extends JPanel implements Runnable {
JButton jb1, jb2, jb3, jb4;

JPanel panel1, panel2, panel3, panel4;

static int index = 0;

Container cont;

MyPanel() {
//
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
//
jb1 = new JButton("1");

jb2 = new JButton("2");

jb3 = new JButton("3");

jb4 = new JButton("4");
//

panel1.add(jb1);
panel2.add(jb2);
panel3.add(jb3);
panel4.add(jb4);

setLayout(new GridLayout(2, 2));

this.setNewColor();

this.add(panel1);
this.add(panel2);
this.add(panel3);
this.add(panel4);
Thread thread = new Thread(this);
thread.start();
}

public void setNewColor() {

//
panel1.setBackground(new Color((int) (Math.random() * 255), (int) (Math
.random() * 255), (int) (Math.random() * 255)));
panel2.setBackground(new Color((int) (Math.random() * 255), (int) (Math
.random() * 255), (int) (Math.random() * 255)));

panel3.setBackground(new Color((int) (Math.random() * 255), (int) (Math
.random() * 255), (int) (Math.random() * 255)));
panel4.setBackground(new Color((int) (Math.random() * 255), (int) (Math
.random() * 255), (int) (Math.random() * 255)));

}

public void run() {

while (true) {
try {
Thread.sleep(150);
this.setNewColor();
System.out.print("background color is changed!\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}

}[/code]

不知道这个是不是你想要的效果


littledeer1974 edited on 2004-10-25 09:42


话题树型展开
人气 标题 作者 字数 发贴时间
7133 请教高手,背景颜色的不间断随机变化 flywithmoon 2471 2004-08-24 22:40
6023 Re:请教高手,背景颜色的不间断随机变化 flywithmoon 14 2004-08-26 09:25
7148 Re:请教高手,背景颜色的不间断随机变化 littledeer1974 2314 2004-08-27 16:24
5883 Re:请教高手,背景颜色的不间断随机变化 flywithmoon 56 2004-08-27 16:55
6839 Re:请教高手,背景颜色的不间断随机变化 littledeer1974 52 2004-08-27 23:20
6955 Re:请教高手,背景颜色的不间断随机变化 littledeer1974 88 2004-08-27 23:25
5831 Re:请教高手,背景颜色的不间断随机变化 flywithmoon 59 2004-08-30 10:39
6901 Re:请教高手,背景颜色的不间断随机变化 littledeer1974 88 2004-08-30 15:43

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923