我使用NET Beans IDE在LINUX中开发我的应用程序。我已经使用synthetica包来生成新的外观和感觉。到现在为止一切都很好。
现在,我的下一步是在某些数据库状态发生变化时为按钮添加颜色。
例如:
在一家餐馆里,我有两张桌子,当8个人进来用餐时,我会在我的软件中创建2张桌子,因为这些人是无人照看的,我希望这两张桌子的按钮是绿色的。当为这些表中的任何一个处理订单时,处理的表的按钮颜色应该更改为橙色。当它正在处理时,它应该是闪烁的颜色。如何在java中做到这一点?我会处理数据库的更新,我只想知道如何改变按钮的颜色和添加闪烁技术。
发布于 2010-08-06 09:33:56
这是一个与刷新组件相关的 question and several answers。
附录:您可以在文章中了解更多信息。特别是,您可以使用setForeground()来更改按钮文本的颜色,但是相应的setBackground()在某些平台上不能很好地阅读。使用Border是一种选择;下面显示的彩色面板是另一种选择。

package overflow;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class ButtonTest extends JPanel implements ActionListener {
private static final int N = 4;
private static final Random rnd = new Random();
private final Timer timer = new Timer(1000, this);
private final List<ButtonPanel> panels = new ArrayList<ButtonPanel>();
public ButtonTest() {
this.setLayout(new GridLayout(N, N, N, N));
for (int i = 0; i < N * N; i++) {
ButtonPanel bp = new ButtonPanel(i);
panels.add(bp);
this.add(bp);
}
}
@Override
public void actionPerformed(ActionEvent e) {
for (JPanel p : panels) {
p.setBackground(new Color(rnd.nextInt()));
}
}
private static class ButtonPanel extends JPanel {
public ButtonPanel(int i) {
this.setBackground(new Color(rnd.nextInt()));
this.add(new JButton("Button " + String.valueOf(i)));
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame("ButtonTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ButtonTest bt = new ButtonTest();
f.add(bt);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
bt.timer.start();
}
});
}
}https://stackoverflow.com/questions/3420311
复制相似问题