문제

나를 부르 youtubeviewer 에서 창 actionlistener

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 를 들어(테스트)

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);
}
}

YouTubeViewer 포함 클래스의 DJ 네이티브 스윙 api 라이브러리입니다.

는 경우에 전화로 직접 주요 기능이 작동합니다.하지만 만약 내가 부르에서 actionlistener 그것은 응답하지 않는 시간에 나는 그것을 누르~내 생각은 그것이 문제가 실행의 문제를~를 해결하는 방법?어떤 생각이 있으십니까?감사 어떤 생각이 있으십니까??

도움이 되었습니까?

해결책

귀하의 코드 블록 EDT(NativeInterface.runEventPump();).그래서 당신은 그것을 해야 하에서 다른 스레드가 있습니다.

public void actionPerformed(ActionEvent actionEvent)
{
       Thread t = new Thread(new Runnable() {
         public void run() {
           YouTubeViewer a = new YouTubeViewer();
         }
       });
       t.start();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top