我想知道是否有任何庫或其他類似BUZZ動畫的JFrames! yahoo messenger中的動畫,如果沒有現成的庫這樣做,那麼可能的算法是什麼呢?如何製作JFrame動畫?
0
A
回答
3
你可以創建你的自己的Buzz方法爲你工作的框架克。看看下面給出的代碼。
編輯 正如MadProgrammer和DavidKroukamp建議的那樣,我已經更改了代碼以符合標準。 :)
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class BuzzFrame extends JFrame
{
private JButton buzz = new JButton("BUZZ ME!!");
public BuzzFrame()
{
super("BUZZ Frame!!");
}
public void prepareGUI()
{
buzz.addActionListener(new BuzzActionListener(this));
setSize(300,200);
getContentPane().add(buzz,BorderLayout.NORTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String st[])
{
SwingUtilities.invokeLater (new Runnable()
{
@Override
public void run()
{
BuzzFrame bFrame = new BuzzFrame();
bFrame.prepareGUI();
bFrame.setVisible(true);
}
});
}
}
class BuzzActionListener implements ActionListener
{
private JFrame frame;
private Point currLocation;
private int iDisplaceXBy = 5;
private int iDisplaceYBy = -10;
public BuzzActionListener(JFrame frame)
{
this.frame = frame;
}
@Override
public void actionPerformed(ActionEvent evt)
{
currLocation = frame.getLocationOnScreen();
fireBuzzAction();
}
private void fireBuzzAction()
{
SwingUtilities.invokeLater (new Runnable()
{
@Override
public void run()
{
Point position1 = new Point(currLocation.x + iDisplaceXBy , currLocation.y + iDisplaceYBy);
Point position2 = new Point(currLocation.x - iDisplaceXBy , currLocation.y - iDisplaceYBy);
for (int i = 0; i < 20 ; i++)
{
frame.setLocation(position1);
frame.setLocation(position2);
}
frame.setLocation(currLocation);
}
});
}
}
2
0
我這樣做有一個簡單的函數:
public void ZUMBIDO() {
toFront();
new Thread(new Runnable() {
int milisegundos = 50;
int posiciones = 20;
public void arriba() {
Point pos = getLocation();
pos.translate(0, posiciones);
setLocation(pos);
}
public void abajo() {
Point pos = getLocation();
pos.translate(0, -posiciones);
setLocation(pos);
}
public void derecha() {
Point pos = getLocation();
pos.translate(posiciones, 0);
setLocation(pos);
}
public void izquierda() {
Point pos = getLocation();
pos.translate(-posiciones, 0);
setLocation(pos);
}
public void proceso() {
try {
arriba();
Thread.sleep(milisegundos);
derecha();
Thread.sleep(milisegundos);
abajo();
Thread.sleep(milisegundos);
izquierda();
Thread.sleep(milisegundos);
} catch (InterruptedException ex) {
Logger.getLogger(cliente.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void run() {
for (int i = 0; i <= 5; i++) {
proceso();
}
}
}).start();
}
您可以用下一個代碼,它與回聲概念一個簡單的聊天動作觀看。
相關問題
- 1. 如何製作UIView動畫?
- 2. 如何製作動畫雲?
- 3. 如何製作此動畫?
- 4. 我如何製作動畫?
- 5. 如何製作動畫NSCursor?
- 6. 如何製作平滑的反對者動畫製作動畫?
- 7. 如何製作模態JFrame?
- 8. 如何在JFrame中實現動畫
- 9. 如何刷新Jframe以創建動畫?
- 10. 如何僅在點擊按鈕後才能製作JFrame繪畫?
- 11. 如何製作「搖動」動畫
- 12. 如何使用動畫GIF作爲JFrame標題欄圖標
- 13. 製作動畫
- 14. 如何在JFrame上繪畫
- 15. 如何在動畫製作與非動畫製作時不重複此代碼?
- 16. JFrame滾動條和畫布
- 17. 動畫化JFrame的位置
- 18. JFrame中的窗口動畫
- 19. 使用JFrame創建動畫
- 20. 如何沿着路徑製作動畫
- 21. 如何爲Google圖表製作動畫?
- 22. 如何製作UIView動畫回調?
- 23. 如何製作動畫sidein導航欄?
- 24. 如何製作程序化動畫
- 25. 如何製作動畫按鈕?
- 26. 如何製作流行動畫
- 27. 谷歌如何製作動畫模因?
- 28. 如何製作旋轉動畫
- 29. 如何製作幻燈片動畫?
- 30. 如何製作雨水動畫?
耶不是一個好的做法,但強調的是理念;) –
(@DavidKroukamp我會讓他修理給人一種贊成票之前那些「壞想法」 ......但我是一個憤世嫉俗老混蛋;)) – MadProgrammer
@MadProgrammer非常真實....(不是憤世嫉俗的部分哈哈:P)我正在考慮它.... Vishal K,請你糾正代碼,以便我可以再次投票... ...我現在只能看到'Thread.sleep' ......並且混合了其他不好的做法,問題非常突出。 –