監控網頁內容,發現需要的內容後彈框和聲音提醒
GetMethod getMethod = new GetMethod(newUrl); int statusCode = httpClient.executeMethod(getMethod); byte[] responseBody = getMethod.getResponseBody();
2.解析網頁,查詢是否包含所需要內容
InputStream inputStream = new ByteArrayInputStream(bytes);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
//比較判斷邏輯....
}
3.彈框提醒
import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JLabel; import javax.swing.WindowConstants; public class DialogMessage extends javax.swing.JFrame { private JLabel text; Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); int height = screenSize.height; int width = screenSize.width; private String str = null; public DialogMessage(String str) { this.str = str; new Thread(new Runnable() { @Override public void run() { initGUI(); } }).start(); } private void initGUI() { try { setUndecorated(true); setLocationRelativeTo(null); setVisible(true); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { text = new JLabel("<html>" + str + "</html>", JLabel.CENTER); getContentPane().add(text, BorderLayout.CENTER); text.setBackground(new java.awt.Color(255, 251, 240)); } pack(); setBounds(width - 380, height - 150, 360, 100); try { Thread.sleep(9000); } catch (InterruptedException e1) { e1.printStackTrace(); } dispose(); } catch (Exception e) { e.printStackTrace(); } } }
4.聲音提醒
//Toolkit.getDefaultToolkit().beep();//系統預設提示音
Clip clip = AudioSystem.getClip();//呼叫外部檔案定義的聲音
AudioInputStream inputStream = AudioSystem.getAudioInputStream(SoundMessage.class.getResourceAsStream(url));
clip.open(inputStream);
clip.start();
最後,附上完整程式碼下載地址:http://download.csdn.net/detail/lk_blog/9150901