DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   how to add swf file as JButton (http://www.daniweb.com/forums/thread167868.html)

rude04 Jan 12th, 2009 9:41 am
how to add swf file as JButton
 
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


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class MyPanel extends JPanel {
    private JButton jcomp1;

    public MyPanel() {
        //construct components
        jcomp1 = new JButton ("button.swf");

        //adjust size and set layout
        setPreferredSize (new Dimension (220, 149));
        setLayout (null);

        //add components
        add (jcomp1);

        //set component bounds (only needed by Absolute Positioning)
        jcomp1.setBounds (55, 90, 100, 25);
    }


    public static void main (String[] args) {
        JFrame frame = new JFrame ("MyPanel");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add (new MyPanel());
        frame.pack();
        frame.setVisible (true);
    }
}

masijade Jan 12th, 2009 9:48 am
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?

rude04 Jan 12th, 2009 9:53 am
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..:)

masijade Jan 12th, 2009 10:16 am
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).

peter_budo Jan 12th, 2009 10:24 am
Re: how to add swf file as JButton
 
You better look into Java and Flex

rude04 Jan 12th, 2009 10:25 am
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..

rude04 Jan 12th, 2009 10:29 am
Re: how to add swf file as JButton
 
what is java and flex?


All times are GMT -4. The time now is 8:08 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC