私は Java に比較的慣れていませんが、最近は GUI ベースの html パーサーに取り組んでいます。インターフェイスはシンプルで、次のもので構成されています。
JTextField
検索語を入力するためのJButton
b1 検索を開始するJButton
b2 終了するJButton
b3 を使用して、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 の目的に違反します)。