Swing组件动态滚动效果 (二)

2014-11-24 02:22:12 · 作者: · 浏览: 1
urrentTime = System.nanoTime() / 1000000;
long totalTime = currentTime - cycleStart;

if (totalTime > MOVE_TIME) {
cycleStart = currentTime;
}
float fraction = (float) totalTime / MOVE_TIME;
fraction = Math.min(1.0f, fraction);
fraction = 1 - Math.abs(1 - (2 * fraction));
animate(fraction);
}

public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(400, 70);
frame.getContentPane().add(new AutoComponent());
frame.setUndecorated(true);
XUtil.setComponentCenter(frame);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
frame.setVisible(true);
}
});
}
}