Results 1 to 2 of 2
  1. #1
    usuikazkou is offline Member
    Join Date
    May 2014
    Posts
    5
    Rep Power
    0

    Default how to call this code from gui(jframe)

    i wanna to call youtubeviewer from a window by actionlistener
    and i have tried N times.... please help!!

    Java Code:
    public class YouTubeViewer {
    
        public YouTubeViewer(){
            NativeInterface.open();
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("YouTube Viewer");
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                    frame.getContentPane().add(getBrowserPanel(), BorderLayout.CENTER);
                    frame.setSize(800, 600);
                    frame.setLocationByPlatform(true);
                    frame.setVisible(true);
                } 
            });
            NativeInterface.runEventPump();
            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                @Override
                public void run() {
                    NativeInterface.close();
                }
            }));
        }
    
        public JPanel getBrowserPanel() {
            JPanel webBrowserPanel = new JPanel(new BorderLayout());
            JWebBrowser webBrowser = new JWebBrowser();
            webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
            webBrowser.setBarsVisible(false);
            webBrowser.navigate("www.youtube.com/embed/sKeCX98U29M");
            return webBrowserPanel;
        }
    }
    jframe example(for testing)
    Java Code:
    public class trailerPlayer extends JPanel implements ActionListener
    {
    	private JButton press;
    	public trailerPlayer ()
    	{
    		setLayout(new BorderLayout());
                    press = new JButton("press");
                    press.addActionListener(this);
                    add(press);
    	}
    	public void actionPerformed(ActionEvent actionEvent)
    	{
                   YouTubeViewer a = new YouTubeViewer();
            }
            public static void main(String args[ ])
    	{	
    		trailerPlayer p = new trailerPlayer();	
    		JFrame test = new JFrame();
    
    		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		test.add(p);
    		test.setSize(500,500);
    		test.setVisible(true);
    	}
    }
    note:necessary library for youtubeviewer is DJ Native Swing.

    if i call directly by main function,it will work.but if i call from actionlistener cant work (maybe crash).
    any idea??
    Last edited by usuikazkou; 06-03-2014 at 11:30 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to call this code from gui(jframe)

    duplicate thread; closed.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. how to call this code form gui(jframe)
    By usuikazkou in forum New To Java
    Replies: 4
    Last Post: 06-04-2014, 01:27 PM
  2. Replies: 0
    Last Post: 01-09-2013, 07:12 PM
  3. call JFrame by select JList
    By raj.mscking@gmail.com in forum AWT / Swing
    Replies: 2
    Last Post: 01-30-2012, 08:54 AM
  4. call JFrame 2 from JFrame1: help
    By dottbin in forum AWT / Swing
    Replies: 11
    Last Post: 04-07-2011, 11:16 PM
  5. How to call an XML-RPC method from Java Code
    By sreekanth.srk in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 12-31-2010, 12:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •