Solved

Creating 'help' windows from dialog button

Posted on 1998-04-11
4
174 Views
Last Modified: 2010-04-16
Using MS Vis J++, I've created some dialog windows to get user input.  I added 'help' buttons to the dialog windows, but can't figure out how to display help messages without destroying the dialog window.  The way I've tried is to create new dialog boxes with the help messages in them--and these are called from the action method of the original dialog.  The problem is, I can't return to that dialog, and the program hangs after reading the help dialog.  This is part of a big program, so here's a portion of the applet code.  If there is a way to allow returning to the dialog box, or an easier way to do this, please let me know:

//the dialog frame that calls the help frame
class OurFrame extends Frame
{
      private AutoDialog m_autodialog = null;
      private Applet m_parent = null;      
      public DialogData m_data = null;
      private HelpFrame m_frame3 = null;

      public OurFrame(Applet parent)
      {
            super("Input Window #1");
            m_parent = parent;
            setFont(new Font("Arial", Font.PLAIN, 12));

            m_autodialog = new AutoDialog(this);
            m_autodialog.CreateControls();
            show();
      }
      public boolean action(Event event, Object obj)
      {
            Object target = event.target;
            if (target instanceof Button)
            {
                  Button button = (Button)target;
                  String buttonLabel = button.getLabel();
                  
                  if (buttonLabel.compareTo("Help") == 0)
                  {
                        m_frame3 =new HelpFrame();
                        //m_help1 = new help1(this);
                        //m_help1.CreateControls();
                        //hide();
                        m_parent.repaint();
                        
                  }
                  if (buttonLabel.compareTo("OK")== 0)
                  {
                        String sk = m_autodialog.IDC_EDIT2.getText();
                        boolean a1 = m_autodialog.IDC_RADIO1.getState();//false = .05
            
                        int m_k = Integer.parseInt(sk);            
                        m_data = new DialogData(sk,a1);
                        m_parent.repaint();
                  }
                  hide();
                  return true;
            }
            return false;
      }


//The helpFrame class that the above calls when the help button is clicked:
class HelpFrame extends Frame
{
      private help1 m_help1 = null;
      public HelpFrame()
      {
            super("Help");
            setFont(new Font("Arial", Font.PLAIN, 12));

            m_help1 = new help1(this);
            m_help1.CreateControls();
            show();
      }
      public boolean action(Event event, Object obj)
      {
            Object target = event.target;
            if (target instanceof Button)
            {
                  Button button = (Button)target;
                  String buttonLabel = button.getLabel();
                  if (buttonLabel.compareTo("OK")== 0)
                  {
                        //m_parent3.repaint();
                        repaint();                        
                  }
                              
                  hide();
                  return true;
            }
            return false;
      }
}
0
Comment
Question by:imsap
  • 3
4 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1234044
  You haven't said if its an applet or an application. If its an applet, a good idea will be to use the showDocument method to open a new brawser window hith your help, and to write your help in html. This is probably the easiest way of creating a help system.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1234045
 I see now by your code that it is an applet, so let me know if this direction is good for you, I'll give you some more info about it.
0
 

Author Comment

by:imsap
ID: 1234046
Thanks for the reply.  Actually, I have both an application and applet version.  I also figured out the problem--I left off a "return false" in the call to the help dialogs from the original dialogs.  However, you can have the points if you put in some info about using the ShowDocument to create a new browser page.  This would be helpful for cleaning up my applet output.
0
 
LVL 6

Accepted Solution

by:
gadio earned 100 total points
ID: 1234047
 I will give you a sample code:
Say that you want to give a help on an item, and you have a
-----
file: simpleApplet1.java
-----


import java.applet.*;
import java.awt.*;

public class simpleApplet1 extends Applet {
  TextField text;
  Button b;
  String help_item;

  public simpleApplet1() {
        help_item = new String( "help" );
        text = new TextField(20);
        b = new Button("help_me");
        add( b );
        add( text );
  }

  public boolean handleEvent( Event evt ) {
        if( evt.target == b ) {
          try {
                getAppletContext().showDocument(new java.net.URL(getCodeBase(),help_item+".html"), help_item);
          }
          catch ( java.net.MalformedURLException e ){}
          return true;
        }
        return false;
  }

}


file index.html
----

<html>
<applet code=simpleApplet1.class name=app2 width=190 height=145>
</applet>
</html>


file: help.html
----

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
    <title>help file</title>
  </head>
  <body>
      <h1>help file</h1>
      <hr>
          This is a help about...
  </body>
</html>


---------
Apart from that I'd like to note that sun has a new API for help system. You can check it out at:
http://java.sun.com/products/javahelp/download_spec.html
This help system should fit both applet and application.

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question