943,865 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3090
  • Java RSS
Jan 12th, 2009
0

how to add swf file as JButton

Expand Post »
i want to use a JButton with a rollover sound..so created a button with a sound using adobe macromedia flash...
how can i display it in the swf button in jpanel??
here is the button..button.swf


java Syntax (Toggle Plain Text)
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import javax.swing.event.*;
  5.  
  6. public class MyPanel extends JPanel {
  7. private JButton jcomp1;
  8.  
  9. public MyPanel() {
  10. //construct components
  11. jcomp1 = new JButton ("button.swf");
  12.  
  13. //adjust size and set layout
  14. setPreferredSize (new Dimension (220, 149));
  15. setLayout (null);
  16.  
  17. //add components
  18. add (jcomp1);
  19.  
  20. //set component bounds (only needed by Absolute Positioning)
  21. jcomp1.setBounds (55, 90, 100, 25);
  22. }
  23.  
  24.  
  25. public static void main (String[] args) {
  26. JFrame frame = new JFrame ("MyPanel");
  27. frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  28. frame.getContentPane().add (new MyPanel());
  29. frame.pack();
  30. frame.setVisible (true);
  31. }
  32. }
Last edited by rude04; Jan 12th, 2009 at 9:50 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
rude04 is offline Offline
26 posts
since Jun 2008
Jan 12th, 2009
0

Re: how to add swf file as JButton

Well, I can at least say that that's nicely formatted. Otherwise .....

Did you have some sort of question you wished to ask?
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jan 12th, 2009
0

Re: how to add swf file as JButton

yes..i wanted to use a swf as JButton..how do i do that??
sorry i wasn't done yet with the post when you replied..
Reputation Points: 10
Solved Threads: 0
Light Poster
rude04 is offline Offline
26 posts
since Jun 2008
Jan 12th, 2009
0

Re: how to add swf file as JButton

In that manner, you can't. Create an image that you can create an ImageIcon from to set as the button lable (see the API docs for JButton) and create a Sound file and use a MouseListener to play it with the MouseEntered event (See the Swing tutorials).
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jan 12th, 2009
0

Re: how to add swf file as JButton

You better look into Java and Flex
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Jan 12th, 2009
0

Re: how to add swf file as JButton

.,uhhm..can you give me a sample code??im not really good at these kind of instructions..I'm just new to java prog..the code that i posted was from a software called guigenie,it lets me drag components in the frame and gives the code..
Reputation Points: 10
Solved Threads: 0
Light Poster
rude04 is offline Offline
26 posts
since Jun 2008
Jan 12th, 2009
0

Re: how to add swf file as JButton

what is java and flex?
Reputation Points: 10
Solved Threads: 0
Light Poster
rude04 is offline Offline
26 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: About Pseudorandom Number Generator
Next Thread in Java Forum Timeline: Need to add "java.xml.*" library





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC