2012-03-05 8 views
2

私は、Javaプログラムのプログラム/スタートメニューを作成するためにswingを使用していました。私が望むのは、私のプログラムがアニメーションGIFをバックグラウンドでプレイすることです。一方、gifの特定のセクションには目に見えないボタンがあります(その上にマウスを置くだけでその存在を明らかにします)。私の問題は次のようなものです:アニメーションGIFの背景に非表示のボタンを作成するにはどうすればいいですか?

A)ボタンを押すのを待っている間、アニメーションgifを再生する方法がわかりません。 B)JButtonを非表示にするにはどうすればよいですか?

ありがとうございます、ありがとうございます。

-JXP

+0

*そのために使用することができます "私の問題は、このようにしています:" *。 「使用できないGUI」についてのユーザーからの苦情? 「目に見えないボタン」 - ブリーチ!それらを見えるようにするか、私が使用すると思われるGUIにそれらを入れないでください。このGUIとは何ですか?子供の試合? (もしそうなら、私は自分の気分を変える権利を持っていて、それはかなり好きです;) –

+0

@AndrewThompsonボタンは見えませんが、ボタンにはアニメーションGIFにボタンが含まれています。たとえば、gifはgifで、gifのセクション(ボタンにはstartという単語があります)がボタンになるようにしたいのですが、デフォルトのjavaボタンの1つではなく、ちょうど収まりません。 – JXPheonix

答えて

4

私はSwinggifまたはanimated gifを使用することはありませんが、あなたは、このコード

enter image description hereenter image description here

import java.awt.Insets; 
import java.awt.event.MouseEvent; 
import java.awt.event.MouseListener; 
import javax.swing.Icon; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.SwingUtilities; 
import javax.swing.UIManager; 

public class MyToggleButton extends JFrame { 

    private static final long serialVersionUID = 1L; 
    private Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon"); 
    private Icon infoIcon = UIManager.getIcon("OptionPane.informationIcon"); 
    private Icon warnIcon = UIManager.getIcon("OptionPane.warningIcon"); 

    public MyToggleButton() { 
     final JButton toggleButton = new JButton(); 
     toggleButton.setBorderPainted(false); 
     toggleButton.setBorder(null); 
     toggleButton.setFocusable(false); 
     toggleButton.setMargin(new Insets(0, 0, 0, 0)); 
     toggleButton.setContentAreaFilled(false); 
     toggleButton.setIcon((errorIcon)); 
     toggleButton.setSelectedIcon(infoIcon); 
     toggleButton.setRolloverIcon((infoIcon)); 
     toggleButton.setPressedIcon(warnIcon); 
     toggleButton.setDisabledIcon(warnIcon); 
     add(toggleButton); 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     pack(); 
     setVisible(true); 
    } 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable() { 

      @Override 
      public void run() { 
       MyToggleButton t = new MyToggleButton(); 
      } 
     }); 
    } 
} 
+0

私はこれを試してみる、ありがとう。 – JXPheonix

+0

あなたを助けることができてうれしい – mKorbel

+0

+1 [ここ](http://stackoverflow.com/a/3484251/230513)に見られるように、アニメーションを行うために 'Icon'を実装することもできます。 – trashgod