Results 1 to 2 of 2
  1. #1
    Araganaus is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default Web page refresh

    Hello everyone!
    I'm REALLY a newbie in the java world and I'm in a desperate need of help! :P I'm just trying to develop a simple application integrating a simple web browser. In fact, the application is just a web page with no commands on it. Anyway, I made it to create the web browser and make it render the web page. This by modifying an example that had buttons on it, and removing buttons. Now, I'd need to refresh automatically the page every 60 seconds.. how can I do this? I tryed to put a loop with a Thread.sleep() statement but it kept saying java.lang.interruptedexception.
    Can anyone help me? I just need to refresh that damned page every 60 secs!!
    Thanks a lot!

    Araganaus
    ************************************************
    Here is the code:



    package browsertest;

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;

    public class Browser extends JFrame implements HyperlinkListener,
    ActionListener {


    public static void main(String[] args) {
    byte mac[];
    try {
    InetAddress address = InetAddress.getLocalHost();

    /*
    * Get NetworkInterface for the current host and then read the
    * hardware address.
    */
    NetworkInterface ni = NetworkInterface.getByInetAddress(address);
    mac = ni.getHardwareAddress();
    new Browser("SOMELINK(DOESEN'TALLOWTOPOST!)".concat(by teArrayToHexString(mac)));

    /*
    * Extract each array of mac address and convert it to hexa with the
    * following format 08-00-27-DC-4A-9E.
    */



    } catch (UnknownHostException e) {
    e.printStackTrace();
    } catch (SocketException e) {
    e.printStackTrace();
    }


    }

    private JButton homeButton;
    private JTextField urlField;
    private JEditorPane htmlPane;
    private String initialURL;
    private String currentURL;

    public Browser(String initialURL) {
    super("Golden Fish");
    this.initialURL = initialURL;


    try {
    htmlPane = new JEditorPane(initialURL);
    htmlPane.setEditable(false);
    htmlPane.addHyperlinkListener(this);
    getContentPane().add(htmlPane, BorderLayout.CENTER);
    } catch(IOException ioe) {
    warnUser("Can't build HTML pane for " + initialURL
    + ": " + ioe);
    }

    Dimension screenSize = getToolkit().getScreenSize();
    int width = screenSize.width * 5 / 10;
    int height = screenSize.height * 4 / 10;
    setBounds(width/8, height/8, width, height);
    setVisible(true);

    }

    public void actionPerformed(ActionEvent event) {
    String url;
    if (event.getSource() == urlField)
    url = urlField.getText();
    else // Clicked "home" button instead of entering URL
    url = initialURL;
    try {
    htmlPane.setPage(new URL(url));
    urlField.setText(url);
    } catch(IOException ioe) {
    warnUser("Can't follow link to " + url + ": " + ioe);
    }
    }

    public void hyperlinkUpdate(HyperlinkEvent event) {
    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    try {
    htmlPane.setPage(event.getURL());
    } catch(IOException ioe) {
    warnUser("Can't follow link to "
    + event.getURL().toExternalForm() + ": " + ioe);
    }
    }
    }

    private void warnUser(String message) {
    JOptionPane.showMessageDialog(this, message, "Error",
    JOptionPane.ERROR_MESSAGE);
    }


    static String byteArrayToHexString(byte in[]) {

    byte ch = 0x00;

    if (in == null || in.length <= 0)

    return null;



    String pseudo[] = {"0", "1", "2",
    "3", "4", "5", "6", "7", "8",
    "9", "A", "B", "C", "D", "E",
    "F"};

    StringBuffer out = new StringBuffer(in.length * 2);



    for (int i=0; i < in.length; i++) {

    ch = (byte) (in[i] & 0xF0); // Strip off high nibble

    ch = (byte) (ch >>> 4);
    // shift the bits down

    ch = (byte) (ch & 0x0F);
    // must do this is high order bit is on!

    out.append(pseudo[ (int) ch]); // convert the nibble to a String Character

    ch = (byte) (in[i] & 0x0F); // Strip off low nibble

    out.append(pseudo[ (int) ch]); // convert the nibble to a String Character

    }

    String rslt = new String(out);

    return rslt;

    }
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    I didn't go over your code but you are going to have to use a separate thread and the SwingTimer.

Similar Threads

  1. refresh the jsp page(ajax)
    By lukky in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-28-2008, 10:17 AM
  2. i need to refresh the page again?Help needed
    By 82rathi.angara in forum New To Java
    Replies: 2
    Last Post: 07-29-2008, 02:58 PM
  3. warning that page has expired and i need to refresh the page again
    By 82rathi.angara in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 07-15-2008, 02:48 PM
  4. Refresh the page
    By udhayageetha in forum AWT / Swing
    Replies: 2
    Last Post: 07-01-2008, 10:03 AM
  5. How to Refresh the same page by JSP
    By AbuAziz in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-10-2007, 05:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •