您好我刚刚用Java完成了我的第一个小程序: http://st.fri.uniza.sk/~mudrak3/index2
它的作用基本上是通过网站源代码找到任何链接并将它们附加到textArea中。
如果我将该网站链接放入textField(http://st.fri.uniza.sk/~mudrak3/index2)并按下按钮,则一切正常。按钮事件:
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
textArea1.setText("\f");
try {
ArrayList<String> array = new ArrayList<String>();
ArrayList<String> vystup = new ArrayList<String>();
URL adresa;
adresa = new URL(textField1.getText());
BufferedReader kod = new BufferedReader(new InputStreamReader(adresa.openStream()));
String riadok;
while ((riadok = kod.readLine()) != null) {
array.add(riadok);
String[] pom = riadok.split(" ");
String xxx;
Pattern pattern = Pattern.compile("http://[^ \"]+");
for (int i = 0; i < pom.length; i++) {
xxx = pom[i];
Matcher matcher = pattern.matcher(xxx);
if (matcher.find()) {
textArea1.append(matcher.group(0) + "\n");
}
}
}
textArea1.append("---------Koniec---------");
} catch (MalformedURLException ex) {
JOptionPane.showMessageDialog(null, "Zle zadana URL !");
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "IOException !");
}
}
任何其他网站都不起作用。当我运行applet时,此应用程序在NetBeans中运行,但不在网站上。有帮助吗?