2

私は Java に比較的慣れていませんが、最近は GUI ベースの html パーサーに取り組んでいます。インターフェイスはシンプルで、次のもので構成されています。

  1. JTextField検索語を入力するための
  2. JButtonb1 検索を開始する
  3. JButtonb2 終了する
  4. JButtonb3 を使用して、cmd prmt を使用してブラウザーに URL を表示します。

問題は b3 で発生します。コードサンプルは次のとおりです。

while (mstyle2.find()) 
{
    String s=mstyle2.group(0);
    String pattern = "(?i)(<cite.*?>)(.+?)(</cite>)";
    String updated = s.replaceAll(pattern, "$2"); 
    String pattern2 = "(?i)(<b>)(.+?)(</b>)";
    String updated2 = updated.replaceAll(pattern2, "$2"); 
    String pattern3 = "(http://)";
    boolean c=true;
    String updated32 = updated2.replaceAll(pattern3, ""); 
    String pattern32 = "(https://)";
    final String updated3 = updated32.replaceAll(pattern32,""); 

    try {
        URL url2 = new URL("http://"+updated3);
        URLConnection conne = url2.openConnection();
        conne.connect();
    } catch (MalformedURLException e) {
        c=false;
    } catch (IOException e) {
        c=false;//checks validity of url 
    }

    if(c) {
        Process p=Runtime.getRuntime().exec("cmd /c start http://"+updated3);
    }
}

次のコマンド ラインは、b3 が押されたときにのみ実行する必要があるという考えです。そうしないと、ループは実行されず、ボタンが押されるまでその行に留まります。

Process p=Runtime.getRuntime().exec("cmd /c start http://"+updated3);

ただし、これを可能にするためにメソッドを適切に実装する実行可能な方法が見つかりませんActionListener

私の試行のほとんどでは、b3 が押されると、b3 をクリックするたびに 1 つずつではなく、すべてのリンクが一度に開きます (したがって、b3 の目的に違反します)。

4

1 に答える 1