當前位置:首頁 » 編程語言 » 動畫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文件放在同一文件夾下,然後運行就可以了·~~
熱點內容
python修改文件某一行 發布:2024-05-05 22:18:22 瀏覽:456
md5加密64 發布:2024-05-05 21:59:30 瀏覽:526
259pp頁面訪問升級 發布:2024-05-05 21:47:51 瀏覽:88
迅雷阻止上傳 發布:2024-05-05 21:26:19 瀏覽:913
資料庫運維題 發布:2024-05-05 21:21:47 瀏覽:961
RM魔塔編程 發布:2024-05-05 21:21:47 瀏覽:285
matlab獲取文件夾 發布:2024-05-05 21:12:24 瀏覽:291
一根式演算法 發布:2024-05-05 21:12:23 瀏覽:955
php無刷新 發布:2024-05-05 21:08:11 瀏覽:982
搭建一個流媒體伺服器 發布:2024-05-05 20:40:59 瀏覽:667