2011-12-20 6 views
0

こんにちは、私はJeditorPaneで特定のURLを開くアプリケーションをswingで作成しています。今私はJEditorpaneのコンテンツを自動的にリロードしてほしい。クリックボタンを実行するコードはAutomaticlly特定の時間内にJButtonのClickイベントを実行する

loadButton = new JButton("Load"); 
     loadButton.addActionListener(new ActionListener() 
     { 

      public void actionPerformed(ActionEvent event) 
      { 
       try 
       { 
        // remember URL for back button 
        urlStack.push(url.getText()); 

        editorPane.setPage(url.getText()); 


       } 
       catch(Exception e) 
       { 
        editorPane.setText("Error: " +e); 
       } 

      } 

     }); 

30秒ごとに実行します。これどうやってするの。

答えて

1

タイマー

にアクション/ -listenerを再使用
Action loadAction = new AbstractAction("Load") { 
     public void actionPerformed(...) { 
      // do stuff 
     } 
} 
JButton loadButton = new JButton(loadAction); 
Timer timer = new Timer(30000, loadAction); 
関連する問題