Jump to content
  • Advertisement
Sign in to follow this  
HellCreator

[java] Back and Home Buttons - any suggestions,some one?

This topic is 4849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my App I have html file viewer that gives to user ability of context help about the programm The problem is: if the page have back or home link - no problem to return via this link but if page dont contents those links such as javadoc generated documentation for example or if I need return to index page then only closing frame helps this is the actual code. May be some link onclick listener posible here or some way to remember where I am what the curent page?Or may be to implement onkeylistener and respond let say on key H (home) and jump to index page? But more appreciate way is to return to previous page method! Your suggestions wellcomed and appreciated :)
public class W3D_HelpContext extends  JFrame
//implements ActionListener        // Listener
{ 
	JEditorPane html;	       
     	private static final int TFSPX=0;//window starts position
     	private static final int TFSPY=0;
     	private static final int TFDX=640;//window dimensions
     	private static final int TFDY=480; 
     	private static final String []topics=
                                  {"begining",
                                   "tutorial",
                                   "troubleshooting",
                                   "PTL"};
 public W3D_HelpContext (int id)
      {
      	super("Help");        
        setBounds(TFSPX,TFSPY,TFDX,TFDY);
   		try {
	    URL url = null;
	    String path = null;
	    try {
		path = "HELP/";
		if(id>=0&&id<100)path+=topics[id];
		else path+="index";
		path+=".html";
		url = getClass().getResource(path);
            } catch (Exception e) {
		if(W3D_C.debug){System.out.println("Failed to open " + path);}
		url = null;
            }
            if(url != null) {
                html = new JEditorPane(url);
                html.setEditable(false);
                html.addHyperlinkListener(createHyperLinkListener());
		JScrollPane scroller = new JScrollPane();
		JViewport vp = scroller.getViewport();
		vp.add(html);
                getContentPane().add(scroller, BorderLayout.CENTER);
            }
        } catch (MalformedURLException e) {
            if(W3D_C.debug){System.out.println("Malformed URL: " + e);}
        } catch (IOException e) {
            if(W3D_C.debug){System.out.println("IOException: " + e);}
        }
        pack();  
   	setSize(TFDX,TFDY); 
        setVisible(true);
        setResizable(false);
   }
    public HyperlinkListener createHyperLinkListener() 
    {
	return new HyperlinkListener() {
	    public void hyperlinkUpdate(HyperlinkEvent e) {
		if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
		    if(e instanceof HTMLFrameHyperlinkEvent)
                      {
			((HTMLDocument)html.getDocument()).processHTMLFrameHyperlinkEvent(
			    (HTMLFrameHyperlinkEvent)e);
		    } else {
			try {
			       html.setPage(e.getURL());
			    } catch (IOException ioe) 
                             {
			     if(W3D_C.debug){System.out.println("IOE: " + ioe);}
			     }
		    }
		}
	    }
	};
    }
   }

[Edited by - HellCreator on February 22, 2005 3:50:46 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!