當前位置:首頁 » 編程語言 » 動畫java

動畫java

發布時間: 2024-04-26 01:02:40

① 怎麼用java做動畫

重寫paint方法,來實現將自己定義的圖片繪制到組件中,然後啟動一個線程來控制paint方法。 示例: ××××××××××××××××××××××××××× import javax.swing.*; import java.awt.*; class MyPanel extends JPanel implements Runnable { private Image img; private int i=0; private int j=0; public MyPanel() { img=new ImageIcon("1.png").getImage(); } public void paint(Graphics g) { g.drawImage(img,0,0,60,104,i*60,j*104,i*60+60,j*104+104,this); } public void run() { while(true) { while(j { while(i { try { Thread.sleep(300); } catch(Exception e) { } this.repaint(); i++; } j++; i=0; } i=0; j=0; } } } public class test extends JFrame { private MyPanel p; public test() { p=new MyPanel(); this.add(p,BorderLayout.CENTER); this.setBounds(300,200,300,300); this.setTitle("人物行走圖"); new Thread(p).start(); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String args[]) { new test(); } } ××××××××××××××××××××××× 將以上源碼保存為:test.java,編譯,然後下載下面的圖片 將下載的圖片改名為1.png" target="_blank" >



,然後將其和編譯後生成的class文件放在同一文件夾下,然後運行就可以了·~~
熱點內容
數據結構編譯器哪個好 發布:2025-09-18 04:33:52 瀏覽:435
ad轉換c語言 發布:2025-09-18 04:21:21 瀏覽:752
sqlserver2008設置外鍵 發布:2025-09-18 04:21:12 瀏覽:114
伺服器電腦電源管理 發布:2025-09-18 03:52:33 瀏覽:324
叉叉助手刪除腳本 發布:2025-09-18 03:21:24 瀏覽:851
深圳ug五軸編程培訓 發布:2025-09-18 03:13:35 瀏覽:197
安卓軟體殘留怎麼清理 發布:2025-09-18 03:02:02 瀏覽:345
centos7apachephp7 發布:2025-09-18 03:01:47 瀏覽:657
安卓如何實現點擊彈出列表 發布:2025-09-18 02:47:25 瀏覽:58
python文件函數 發布:2025-09-18 02:47:23 瀏覽:574