Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Norm

Thread: how to call this code form gui(jframe)

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

    Default how to call this code form 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??

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

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

    When it crashes what error do you get?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    usuikazkou is offline Member
    Join Date
    May 2014
    Posts
    5
    Rep Power
    0

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

    actually i didnt get any error. after i press the button ,it just stopped responding, not really crash,still running behind. i wonder if this problem cause by running issue?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

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

    ,it just stopped responding
    What was the last statement that executed before it stopped? Add some println() statements to the code so you can see where it was executing (the println prints) and where it did not execute (the println did not print).

    One problem may be that the code is using the EDT to execute YouTubeViewer() instead of executing it on a new thread.
    usuikazkou likes this.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    usuikazkou is offline Member
    Join Date
    May 2014
    Posts
    5
    Rep Power
    0

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

    Quote Originally Posted by Norm View Post
    What was the last statement that executed before it stopped? Add some println() statements to the code so you can see where it was executing (the println prints) and where it did not execute (the println did not print).

    One problem may be that the code is using the EDT to execute YouTubeViewer() instead of executing it on a new thread.
    thanks~ problem solved

Similar Threads

  1. Replies: 0
    Last Post: 01-09-2013, 07:12 PM
  2. Netbeans jpanel form add jframe form
    By modo91 in forum NetBeans
    Replies: 6
    Last Post: 09-10-2012, 07:08 AM
  3. Replies: 6
    Last Post: 01-15-2012, 04:01 AM
  4. opening a Jframe form in a top of a new form
    By Nubkadiya in forum New To Java
    Replies: 7
    Last Post: 06-01-2010, 08:21 PM
  5. Replies: 1
    Last Post: 05-27-2010, 09:48 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
  •