Java Netbeans、JButton在延迟后出现
有谁能告诉我一个JButton在短时间延迟后是如何出现的吗?我正在使用Netbeans—所有组件的拖放概念。我个人会考虑创建一个类来扩展JButton并重写paint方法。使用这两个JTimer可以随时间更改“setComposite()”(在graphics2D类中找到)方法的值 在java中更改组合的示例: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)
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);
}
});
}
}
您也可以查看示例谢谢。我得到了答案。