Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Netbeans、JButton在延迟后出现_Java_Animation_Jbutton - Fatal编程技术网

Java Netbeans、JButton在延迟后出现

Java Netbeans、JButton在延迟后出现,java,animation,jbutton,Java,Animation,Jbutton,有谁能告诉我一个JButton在短时间延迟后是如何出现的吗?我正在使用Netbeans—所有组件的拖放概念。我个人会考虑创建一个类来扩展JButton并重写paint方法。使用这两个JTimer可以随时间更改“setComposite()”(在graphics2D类中找到)方法的值 在java中更改组合的示例: AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)

有谁能告诉我一个JButton在短时间延迟后是如何出现的吗?我正在使用Netbeans—所有组件的拖放概念。

我个人会考虑创建一个类来扩展JButton并重写paint方法。使用这两个JTimer可以随时间更改“setComposite()”(在graphics2D类中找到)方法的值

在java中更改组合的示例:

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

g2d.setComposite(newComposite);

下面是我找到的代码,上面的问题是在它上面工作的

  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);
              }
          });
      }
  }

您也可以查看示例谢谢。我得到了答案。