Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java Swing Question

  • 16-04-2004 09: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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 6,344 ✭✭✭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, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


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


  • Registered Users, Registered Users 2 Posts: 6,344 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 6,344 ✭✭✭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