Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Swing Question

Options
  • 16-04-2004 9:45am
    #1
    Closed Accounts Posts: 2,951 ✭✭✭


    Hi,

    Im messing around with a swing application, and i want the help menu, when my "contents" button is pressed, to launch internet explorer on a page which ill of written up a help document. Is this even possible?
    At the minute i have it bringing up a simple message box eg.

    contentsMenu.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    JOptionPane.showMessageDialog(desktop, "Content ... (enter text here, in the SimpleGUI.java, line 240");


    Thanks


Comments

  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    Im not sure about opening up an Internet explorer window, but you cud create a very basic web browser yourself in Java and then open the help file in that. It might just make your program look a bit more integrated as well. Im not sure of the classes necessary off hand although Im sure the browser window is a derivative of a JTextBox or some such.


  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    Ok it was bugging me so I had to google. Its a JEditorPane that can render HTML docs. Heres a simple example:

    http://www.cafeaulait.org/slides/sd2000east/webclient/24.html


  • Registered Users Posts: 6,306 ✭✭✭OfflerCrocGod


    The way to do it is to start the process iexplore with the argument the location of your webpage i.e.:D go to run and type in -> iexplore google.com that will open up IE on google.


  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    but he wants to do it from his java program no? maybe im just dim


  • Registered Users Posts: 6,306 ✭✭✭OfflerCrocGod


    I dont know? - he asked for IE I told him how to get it it's up to him if he goes for IE by the way here is the code for LinkFollower(I believe). I haven't actually got this to work.

    import javax.swing.*;
    import javax.swing.event.*;


    public class LinkFollower implements HyperlinkListener {

    private JEditorPane pane;

    public LinkFollower(JEditorPane pane) {
    this.pane = pane;
    }

    public void hyperlinkUpdate(HyperlinkEvent evt) {

    if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    try {
    pane.setPage(evt.getURL());
    }
    catch (Exception e) {
    }
    }

    }

    }


  • Advertisement
  • Closed Accounts Posts: 2,951 ✭✭✭L5


    Thanks for the help. Yeah i want to run it from my java program. Ill give these suggestions a shot and see how they work.


  • Closed Accounts Posts: 39 GillyS


    Check out the following - I've used it for a while and it works fine:

    BrowserLauncher

    Gilly


  • Registered Users Posts: 491 ✭✭Silent Bob


    Java is also perfectly capable of forking and execing processes in a similar manner to the *nix system calls.

    Go look at Runtime.exec(...)

    Couple of caveats though:
    • Java forks the process and reserves the exact same amount of memory for the forked process as the forking process was using. Net result: you can have a simple ls process take up 64MB of RAM.
    • Forking a process specific to one operating system makes your program completely non-portable.


  • Registered Users Posts: 6,306 ✭✭✭OfflerCrocGod


    Ye what Silent Bob is on about is what I suggested - by the way I've just fully woken up now and realised why the code wasn't working - I'm behind a firewall/proxy:rolleyes:, sorry about that :p.


  • Closed Accounts Posts: 2,951 ✭✭✭L5


    GillyS, that browserlauncher worked. It was really easy to get working with it. Thanks!


  • Advertisement
Advertisement