Java
  Home arrow Java arrow Page 2 - Java Help Files
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Java Help Files
By: Peter Lavin
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 63
    2004-07-21

    Table of Contents:
  • Java Help Files
  • The Code
  • The HelpWindow Class
  • Enhancements

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Java Help Files - The Code
    (Page 2 of 4 )

    Find below a complete listing of the code in our class. Have a quick look at it now, but don’t worry if you don’t understand all the details. Some basic knowledge of Java is assumed so not all the lines of code will be discussed. Relevant sections will be explained in detail.

       1://////////////////////////////////////////////////////////////////
       2:/**
       3:* This class creates a frame with a JEditorPane for loading HTML
       4:* help files
       5:*/
       6://package goes here
       7:import java.io.*;
       8:import javax.swing.event.*;
       9:import javax.swing.*;
      10:import java.net.*;
      11:import java.awt.event.*;
      12:import java.awt.*;
      13:
      14:public class HelpWindow extends JFrame implements ActionListener{
      15:    private final int WIDTH = 600;
      16:    private final int HEIGHT = 400;
      17:    private JEditorPane editorpane;
      18:    private URL helpURL;
      19://////////////////////////////////////////////////////////////////
      20:/**
      21: * HelpWindow constructor
      22: * @param String and URL
      23: */
      24:public HelpWindow(String title, URL hlpURL) {
      25:    super(title);
      26:    helpURL = hlpURL; 
      27:    editorpane = new JEditorPane();
      28:    editorpane.setEditable(false);
      29:    try {
      30:        editorpane.setPage(helpURL);
      31:    } catch (Exception ex) {
      32:        ex.printStackTrace();
      33:    }
      34:    //anonymous inner listener
      35:    editorpane.addHyperlinkListener(new HyperlinkListener() {
      36:        public void hyperlinkUpdate(HyperlinkEvent ev) {
      37:            try {
      38:                if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      39:                    editorpane.setPage(ev.getURL());
      40:                }
      41:            } catch (IOException ex) {
      42:                //put message in window
      43:                ex.printStackTrace();
      44:            }
      45:        }
      46:    });
      47:    getContentPane().add(new JScrollPane(editorpane));
      48:    addButtons();
      49:    // no need for listener just dispose
      50:    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      51:    // dynamically set location
      52:    calculateLocation();
      53:    setVisible(true);
      54:    // end constructor
      55:}
      56:/**
      57: * An Actionlistener so must implement this method
      58: *
      59: */
      60:public void actionPerformed(ActionEvent e) {
      61:    String strAction = e.getActionCommand();
      62:    URL tempURL;
      63:    try {
      64:        if (strAction == "Contents") {
      65:            tempURL = editorpane.getPage();
      66:            editorpane.setPage(helpURL);
      67:        }
      68:        if (strAction == "Close") {
      69:            // more portable if delegated
      70:            processWindowEvent(new WindowEvent(this,
      71:                WindowEvent.WINDOW_CLOSING));
      72:        }
      73:    } catch (IOException ex) {
      74:        ex.printStackTrace();
      75:    }
      76:}
      77:/**
      78: * add buttons at the south
      79: */
      80:private void addButtons() {
      81:    JButton btncontents = new JButton("Contents");
      82:    btncontents.addActionListener(this);
      83:    JButton btnclose = new JButton("Close");
      84:    btnclose.addActionListener(this);
      85:    //put into JPanel
      86:    JPanel panebuttons = new JPanel();
      87:    panebuttons.add(btncontents);
      88:    panebuttons.add(btnclose);
      89:    //add panel south
      90:    getContentPane().add(panebuttons, BorderLayout.SOUTH);
      91:}
      92:/**
      93: * locate in middle of screen
      94: */
      95:private void calculateLocation() {
      96:    Dimension screendim = Toolkit.getDefaultToolkit().getScreenSize();
      97:    setSize(new Dimension(WIDTH, HEIGHT));
      98:    int locationx = (screendim.width - WIDTH) / 2;
      99:    int locationy = (screendim.height - HEIGHT) / 2;
    100:    setLocation(locationx, locationy);
    101:}
    102:public static void main(String [] args){  
     103:    URL index = ClassLoader.getSystemResource("index.html");
    104:    new HelpWindow("Test", index);
    105:
    106:}
    107:}//end HelpWindow class
    108:////////////////////////////////////////////////////////////////


    More Java Articles
    More By Peter Lavin


       · Using Sun's free JavaHelp API is probably much easier than doing it yourself....
       · I agree thats worth checking into but sometimes you want to customize it to your own...
       · maybe, but consider scalability in rolling your own help - if your application...
       · When using JavaHelp be sure to check out the open source authoring tool JHelpDev at...
       · i hava no comment but i need ur help can u do this kind of exercisecan u help i am...
       · <a href="http://www.hausarbeit-hausaufgabe.de.pn">hausarbeit</a> <a...
       · I am a new Java user and found the HelpWindow class to be useful in an application...
     

       

    JAVA ARTICLES

    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup
    - Using RPC-Style Web Services with J2EE
    - Integrating XML with J2EE
    - Taming Tiger: Concurrent Collections

    Iron Speed



    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway