0

Can any one tell me how a JButton appears[Fade in], after a short delay.I am working with Netbeans - drag and drop concept for all components.

4

2 回答 2

0

就个人而言,我会考虑制作一个扩展您的 JButton 并覆盖paint方法的类。使用 JTimer 随时间更改“setComposite()”(在 graphics2D 类中找到)方法的值。

在java中更改复合的示例:

AlphaComposite newComposite = 
    AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)

g2d.setComposite(newComposite);
于 2012-11-27T08:58:30.240 回答
0

这是我发现上述问题起作用的代码。

  import java.awt.Color;
  import java.util.Timer;
  import java.util.TimerTask;

  public class delay extends javax.swing.JFrame {
      Timer timer;

      public delay(int seconds) {
          initComponents();
          jButton1.setVisible(false);
          getContentPane().setBackground(Color.red);
          timer = new Timer();
          timer.schedule(new RemindTask(), seconds*1000);
      }

      class RemindTask extends TimerTask{
          public void run() {
              jButton1.setVisible(true);
              timer.cancel();        
          }
      }

      public static void main(String args[]) {
          java.awt.EventQueue.invokeLater(new Runnable() {

              public void run() {
                  new delay(5).setVisible(true);
              }
          });
      }
  }
于 2012-11-27T11:33:09.847 回答